Is it possible to access System.Web.HttpContext.Current in a ASP.NET core project targeting the .NET framework . It currently returns null .
Is using Microsoft.AspNetCore.Mvc.HttpContext the only way to go about it ?
Is it possible to access System.Web.HttpContext.Current in a ASP.NET core project targeting the .NET framework . It currently returns null .
Is using Microsoft.AspNetCore.Mvc.HttpContext the only way to go about it ?
you can use the IHttpContextAccessor helper service to get the HTTP context in any class that is managed by the ASP.NET Core dependency injection system. This is useful when you have a common service that is used by your controllers.
public MyClass(IHttpContextAccessor httpContextAccessor){
_httpContextAccessor = httpContextAccessor;
}
you can then access the current HTTP context in a safe way:
var context = _httpContextAccessor.HttpContext;
if this is what your asking for.