form验证,登录后为什么一会儿就自动登录超时,要求重新登录呢?
登录代码为:
//设置登陆信息
string Role="Administrator";//角色:管理员
//建立role-based认证票据
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,Name,DateTime.Now,DateTime.Now.AddMinutes(120),true,Role);
//修改票据cookie,使其加密(本质是写入一个与票据cookie同名的新cookie)
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket);
authCookie.Expires = DateTime.Now.AddMinutes(120);
//cookie的有效时间
Response.Cookies.Add(authCookie);
//重新定向到请求的URL.不要使用FormsAuthentication.RedirectFromLoginPage方法,因为这个方法会重写cookie
string url = FormsAuthentication.GetRedirectUrl(Name,false);
if(url.ToLower().IndexOf("default.aspx") > 0)
{
url = "setup.aspx";
}
Response.Redirect(url);
web.config文件里,timeout=120
后台页面是5分钟刷新一次,管理员登录后,离开一会,再回来就跳到了登录页面...
老大要求:只要浏览器不关,登录后就永不会超时.关闭后就需要重新登录.目前的form验证最好不要改.