I implemented user authentication in ASP.NET MVC. If a valid user tries to log in, I set HttpContext.User = user in the login method of AccountController. But he remains there only for this request. How can I set it for a session?
I used an alternative, set HttpContext.Session["CurrentUser"] = user . If I want to know if a session is allowed, I need to check that HttpContext.User != null . But I do not want to reveal the authentication logic everywhere in the application. If I need to change this, it will be dirty.
Please help me solve this problem. One solution might be to populate the HttpContext.User property for each request with the HttpContext.Session["CurrentUser"] value at the beginning, but I don't know how to do it.
asp.net-mvc
Abdulsattar mohammed
source share