HttpContext is null for MVC

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 is null.

+5
source share
1 answer

HttpContext refers to the constructor. There is no HttpContext , since they are only created when there is a request.

Moving HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); into action solves the problem.

+11
source

Source: https://habr.com/ru/post/1233432/


All Articles