求救:登录以后不登转
问题是这样的。在服务器端登录没有问题,在客户端登录以后不跳转,还是停留在登录页面。目前怀疑是cookie写不进
代码是这样的
private void btnLogin_Click(object sender, System.EventArgs e)
{
string username = userName.Value;
string userpwd = userPwd.Value;
if(LoginHelper.IsPwdTrue(username,userpwd))
{
string usertype=LoginHelper.GetUserType(username);
if(usertype!= " ")
{FormsAuthentication.Initialize();
int cookieVersion = 1;
bool isPersistent=true;
DateTime expireTime;
if(saveCookieOneDay.Checked)
{
expireTime = DateTime.Now.AddDays(1);
}
else
{
expireTime = DateTime.Now.AddMinutes(30);
}
FormsAuthenticationTicket enTicket = new FormsAuthenticationTicket(cookieVersion,
username,DateTime.Now,expireTime,isPersistent,usertype);
string formsCookieStr = FormsAuthentication.Encrypt(enTicket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,formsCookieStr);
cookie.Path=FormsAuthentication.FormsCookiePath;
cookie.Expires = expireTime;
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(username,isPersistent));
}
else
{
Common.ShowWarn( "没有权限登录,请联系管理员! ");
}
}
else
{
Common.ShowWarn( "登录失败,请检查用户名和密码! ");
}
}
目前怀疑是cookie写不进客户端,但是客户端浏览器改成接受所有cookie也不行,请教各位了。
[解决办法]
debug跟踪一下,看看问题在哪
[解决办法]
是不是这句不起作用?
Response.Redirect(FormsAuthentication.GetRedirectUrl(username,isPersistent));
换成
Response.Write( " <script> self.location.href= 'xx.aspx ' </script> ");这种方法如何?
[解决办法]
在测试的时候最好不要在页面里面是用错误跳转,不方便调试,在完成测试后再使用错误处理。避免信息泄露
[解决办法]
string tt= "newwin= window.open( ' "+Request.ApplicationPath+ "/admin_index.aspx "+ " ' "
+ ", ' ', 'toolbar=no '); ";
Response.Write( " <script language=javascript> ");
Response.Write(tt);
Response.Write( "newwin.moveTo(0,0); ");
Response.Write( "newwin.resizeTo(screen.availWidth,screen.availHeight); ");
Response.Write( "window.opener=null; ");
Response.Write( "window.close(); ");
Response.Write( " </script> ");
你还是测试一下你的页面中的那些关键地方的变量是否存在有效值
[解决办法]
web.config里与登录有关的设置
<authentication mode= "Forms ">
<forms name= ".dzgl " loginUrl= "Login.aspx " protection= "Encryption " path= "/ " slidingExpiration= "false "> </forms>
</authentication>
<authorization>
<deny users= "? " />
</authorization>
defaultUrl你设置了没啊?