asp.net mvc - Set HttpContext.User for the session -
I have applied custom authentication in ASP.NET MVC. If a legitimate user tries to log in, then I use AccountController I set the HttpContext.User = user
in the logon method. But this only remains for that request How can I set it for a session?
I used an option, set HttpContext.Session ["CurrentUser"] = User
. If I want to see that the session is authorized, then I have to see that HttpContext.User! = Null
However, I do not want to expose authentication logic everywhere in the application. If I need to change it, then it will be a mess.
Please help me solve it. A solution can start property with the value of HttpContext.User
to HttpContext.Session ["CurrentUser"]
, but I do not know how to do this.
Write the following method in the Application class of ASX
Zero application_BeginRequest (Object Sender, EventArgs e) {HttpContext.Current.User = HttpContext.Session ["CurrentUser"]; }
Or you have inherited your controllers who can use System.Web.Mvc.Controller's "user" property (note: FormsAuthentication Make sure to call the .setAuthCookie method user login).
Comments
Post a Comment