In this article I will explain why HttpContext.Current not working in ASP.Net Core and what is the alternative solution for using the functionality in ASP.Net Core.
Microsoft has permanently removed HttpContext.Current property from .Net Core and introduced a new interface IHttpContextAccessor for .Net Core.
What is IHttpContextAccessor
The IHttpContextAccessor is an interface for .Net Core for accessing HttpContext property.
This interface needs to be injected as dependency in the Controller and then later used throughout the Controller.
This interface allows us to access the HttpContext property which in turn provides access to Request collection and also the Response property.
Startup class Configuration
You will need to add the AddHttpContextAccessor function in the ConfigureServices method of Startup class as shown below.
public void ConfigureServices(IServiceCollection services)
You will need to import the following namespace.
using Microsoft.AspNetCore.Http;
Using IHttpContextAccessor
In the below example, the IHttpContextAccessor is injected in the Controller and assigned to the private property Accessor and later used to access the HttpContext property.
public class HomeController : Controller
    private IHttpContextAccessor Accessor;
    public HomeController(IHttpContextAccessor _accessor)
        this.Accessor = _accessor;
    public IActionResult Index()
        HttpContext context = this.Accessor.HttpContext;
        return View();
Using HttpContext in ASP.Net Core
Download Code