I recently modified the login for my companies eComm site to have a \"Keep me logged in\" feature. The primary change was to make the forms authentication cookie persistent for
What I found out is that for some reason the cookie can get an inconsistent value. For us it was only some users, in some situations.
Better than raising an error i just propose to log the user out in case of the argumentexception. It doesn't explain the "why", is not completely satisfying (in some ways the "remember me" won't work for some users...) but at least it may keep a normal behavior for the user.
In global.asax:
protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
try
{
var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
//...
//setting user properties with cookie...
//...
}
catch (ArgumentException ex)
{
FormsAuthentication.SignOut();
Response.Redirect("/");
}
}
}
Not even sure the redirect is needed (would have to check).
Hope this helps