Form authentication is logging me out
I am using form authentication for by application and when the form times-out the application logs the user out to login page.
But when I enter my credentials again, the application is not letting the user in. When I try it on another browser it works fine.I thought there might be problem with the cashing or cookies, so I cleared both cache and cookies from the browser. But this is still not working.
I am afraid that some thing might me wrong in my code.
Can some please check?
Many Thanks
protected void ManageRoles(string userid, string role)
{
FormsAuthentication.Initialize();
FormsAuthenticationTicket Authticket = new FormsAuthenticationTicket(1, userid, DateTime.Now, DateTime.Now.AddMinutes(180), true, role, FormsAuthentication.FormsCookieName);
string hash = FormsAuthentication.Encrypt(Authticket);
HttpCookie Authcookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (Authticket.IsPersistent)
{
Authcookie.Expires = Authticket.Expiration;
Response.Cookies.Add(Authcookie);
}
}
Global.asax
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket Authticket = id.Ticket;
string userData = Authticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User开发者_StackOverflow = new GenericPrincipal(id, roles);
}
}
}
}
精彩评论