我正在开发用户认证网站。 我有一个登录页面,“Login.aspx”,其中我提供了一个登录控件。 在web.config,使用表单认证类进行认证
<authentication mode="Forms">
<forms name=".AuthenticationCookie" loginUrl="Login.aspx" protection="All" timeout="60" path="/">
<credentials passwordFormat="Clear">
<user name="Jack" password="Jerry"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="*"/>
</authorization>
在login.aspx.cs页, 我已经提供了,
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (FormsAuthentication.Authenticate(Login1.UserName,Login1.Password))
{
FormsAuthentication.SetAuthCookie(Login1.UserName,true);
Label1.Text = "Login Successful";
Login1.InstructionText = "";
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
Response.Redirect("Success.aspx")
}
else
{
Label1.Text = "You are not an authentic user";
}
}
}
但然而,虽然执行的,而不是去success.aspx 与url http://localhost/Login.aspx?ReturnUrl=%2fSuccess.aspx
这是为什么呢?
我不明白它在做什么。你说“而不是执行到success.aspx ...”它在做什么“而不是”那是什么? – soccerdad 2010-07-08 12:32:21
对不起4 dat ...... 而不是它保留在Login.aspx与上述指定的网址。 – user384636 2010-07-08 12:39:07
在上面的代码中,现在它使用RedirectFromLoginPage,您应该删除SetAuthCookie和Response.Redirect调用。在你这样做之后,如果它仍然存在相同的问题,那么当你在调试器中逐步完成时会看到什么。 FormsAuthentication.Authenticate调用是否成功?如果是这样,它是否会使其进入RedirectFromLoginPage调用?你看到了什么HTTP流量(使用Fiddler - http://www.fiddler2.com/fiddler2/)。 – soccerdad 2010-07-08 15:36:31