I have a pretty vanilla controller:
public class HomeController : Controller
{
private readonly ApplicationUserManager _applicationUserManager;
public HomeController()
{
_applicationUserManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
}
However, when I hit it the HttpContext
it's null.
Clearly HttpContext. Current is not null only if you access it in a thread that handles incoming requests.
ASP.NET MVC 5 for Beginners The HttpContext object constructed by the ASP.NET Core web server acts as a container for a single request. It stores the request and response information, such as the properties of request, request-related services, and any data to/from the request or errors, if there are any.
It is stored in the memory of the server and the value is available for the entire lifetime of the request. Save this answer.
HttpContext
is being referenced in the constructor. There isn't an HttpContext
here as they're only created when there is a request.
Moving HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
to an action solves the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With