我网站登录很奇怪,具体情况是这样的:当用户正常登录到后台后,如果再去访问前台页面,再去操作后台页面时,就出现被注销了用户一样,自动退出来了,且再次登录,即使账号密码全正确,也登录不上,什么反应也没有,就一直停在登录界面。奇怪的是,把网页关了,等过了个把小时,再去打开后台时,却直接进入了,连登录验证都不需要而且有时候长时间没操作,再刷新后台页面时,也会跳转到登录界面,这个是正常的,关键是经常又登录不了,只停在登录界面弄得我莫名奇妙,找不出问题在哪,求高手们帮帮忙,看看。我贴出登录代码:
//登录后验证数据库等操作...略去验证代码...//下面是验证成功后的代码FormsAuthentication.SetAuthCookie(UserNameText.Text.ToString().Trim(), true, FormsAuthentication.FormsCookiePath);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserNameText.Text.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, UserNameText.Text.ToString());
// generate new identity
FormsIdentity identity = new FormsIdentity(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
// write to client.
Response.Cookies.Add(cookie); //定向到请求来的页面
if (Request.QueryString["ReturnUrl"] != null)
{
//判断是否有上一级页面,如果有登陆后返回之前的页面
FormsAuthentication.RedirectFromLoginPage(UserNameText.Text.ToString(), false);
}
else
{
FormsAuthentication.SetAuthCookie(UserNameText.Text.ToString(), false);
Response.Redirect("~/user/");//默认进入用户后台页面
}
//登录后验证数据库等操作...略去验证代码...//下面是验证成功后的代码FormsAuthentication.SetAuthCookie(UserNameText.Text.ToString().Trim(), true, FormsAuthentication.FormsCookiePath);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserNameText.Text.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, UserNameText.Text.ToString());
// generate new identity
FormsIdentity identity = new FormsIdentity(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
// write to client.
Response.Cookies.Add(cookie); //定向到请求来的页面
if (Request.QueryString["ReturnUrl"] != null)
{
//判断是否有上一级页面,如果有登陆后返回之前的页面
FormsAuthentication.RedirectFromLoginPage(UserNameText.Text.ToString(), false);
}
else
{
FormsAuthentication.SetAuthCookie(UserNameText.Text.ToString(), false);
Response.Redirect("~/user/");//默认进入用户后台页面
}
看这句的Cookies
{
System.Web.Security.FormsAuthentication.SetAuthCookie(this.Txt_UserName.Text,false);
}FORM认证
<authentication mode="Forms">
<forms
name=".dddASPX"
loginUrl="~/Login.aspx"
defaultUrl="~/User/"
protection="All"
timeout="60"
path="/"
requireSSL="false"
slidingExpiration="true"
enableCrossAppRedirects="false"
cookieless="UseDeviceProfile"
domain="">
</forms>
<forms name=".dddASPX" loginUrl="Login.aspx" timeout="20" path="/"></forms>
</authentication>
<authorization>
奇怪的是,把网页关了,等过了个把小时,再去打开后台时,却直接进入了,连登录验证都不需要
这句似乎不应该是cookie超时。建议换浏览器在测试下。
World Wide Web Publishing Service 服务停止一会,再去登录就可以了 只是有时候也不管用了,杯具啊