In my application I have used Asp.Net Form Authentication,
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
adminResult.UserName,
DateTime.Now,
DateTime.Now.AddDays(2),
true,
"Administrator",
FormsAuthentication.FormsCookiePath
);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie coockie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
{
coockie.Expires = ticket.Expiration;
}
Response.Cookies.Add(coockie);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Dashboard", "Cockpit");
}
But it’s getting logout in 10 to 15 seconds automatically.
What would be the solution ?
Thanks
May be because of the garbage collector clearing and re-assigning the machine key to your app. Generate a machine key and place it in the web.config
MachineKey is used for ViewState encryption and validation and the
FormAuthenticationuses this key to sign the auth ticket, if you dont specify one in theweb.configit is automatically assigned, but if you yourself specify it the collector wont clear it…HERE is an informative article it may help you understand better the importance/working of MachineKey