I have a basic authentication system on my MVC website in ASP.NET
[HttpPost] public ActionResult Login(LoginViewModel model, string returnUrl) { WebSecurity.Login(model.UserName, model.Password, persistCookie: false) return RedirectToAction("Index", "Home"); }
I also have a UserInfoViewModel class where I store some user information and I use it on different pages.
To avoid creating a UserInfoViewModel every time I need it, I want to save it in the Session on Login method.
public ActionResult Login(LoginViewModel model, string returnUrl) { WebSecurity.Login(model.UserName, model.Password, persistCookie: false) var userInfoViewModel = new UserInfoViewModel(); Session["userInfo"] = userInfoViewModel; return RedirectToLocal(returnUrl); }
Given that I have sensitive information that I rely on inside the UserInfoViewModel , such as IsSuperuser , is it possible to save this object in a session? Will it expire when the user login expires?
Decision
System.Security.Principal.IIdentity for this is done. It stores the AUTH cookie user information that you need, so you do not recount it every time.
Use custom video tourion main objects
Thanks for answers!
source share