I'm using the standard membership feature in ASP.NET MVC 4.
I have a login form that when the user logs in successfully, some user information is retrieved from the database and put in a Session variable which I use in certain parts of the application.
My problem is the following:
When I activate the "Remember me" option it works fine, but the session variable won't never be loaded because this one is actually being loaded during the login validation process, which is now being skipped.
My question would be: is there any way to catch the "Remember me" validation process to put my custom code which will load the session variable I need? (or maybe adding more information to the "remember me" cookie which I can use later?)
Thank you
In your scenario, you can use Global.asax's Session_Start event to fill the User's information.
public class Global : System.Web.HttpApplication
{
protected void Session_Start(object sender, EventArgs e)
{
if (HttpContext.Current.User != null &&
HttpContext.Current.User.Identity.IsAuthenticated &&
HttpContext.Current.Session["MyUserInfo"] == null)
{
// Get the user's information from database and save it to Session.
HttpContext.Current.Session["MyUserInfo"] = "johndoe";
}
}
}
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