Enable to use HttpContext.Current on ASP.NET Core applications.
from NuGet - AspNetCoreCurrentRequestContext
PM > Install-Package AspNetCoreCurrentRequestContext
At first, you have to add CurrentRequestContextMiddleware
to IApplicationBuilder
on Configure
method in Startup
class.
You can use the extension-method that is UseCurrentRequestContext
for doing that.
public class Startup
{
public void Configure(IApplicationBuilder app)
{
// add CurrentRequestContextMiddleware.
app.UseCurrentRequestContext();
}
}
After that, if you call AspNetCoreHttpContext.Current
like HttpContext.Current
on ASP.NET applications, you can use HttpContext
everywhere.
// you can get HttpContext in the current request.
var context = AspNetCoreHttpContext.Current;
under MIT Lisence.