我正在尝试使用我在 ASP.NET v2.0 中的 Membership Providers 范例中找到的一些 教程来配置身份验证。我已按照教程中的示例进行操作,但似乎无法使该FormsAuthentication.RedirectFromPage
方法正常工作。当我尝试登录时,用户凭据通过验证,Membership.ValidateUser
但页面被发送回 Login.aspx 而不是 Default.aspx。这是我的 web.config 中的相关片段:
...
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="60" name="POTOKCookie" requireSSL="false" path="/FormsAuth"
slidingExpiration="true" cookieless="UseCookies" enableCrossAppRedirects="false" defaultUrl="~/Default.aspx"/>
</authentication>
<authorization>
<deny users="?" />
</authorization>
...
<membership defaultProvider="CustomizedProvider">
<providers>
<clear />
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="LoginDB2"
applicationName="POTOK"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0" />
</providers>
</membership>
我已经验证了我的连接字符串是正确的(因为 Membership.ValidateUser 似乎工作得很好)并且正在我的 Login.aspx 页面上为 UI 使用 ASP.NET 登录控件。这是身份验证事件处理程序代码:
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
If (Membership.ValidateUser(Login1.UserName, Login1.Password)) Then
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet)
End If
End Sub
当我访问 url ( http://localhost/Project ) 时,我被带到:http://localhost/Project/Login.aspx,在“登录”之后,我的 url 是:http://localhost/Project/Login。 aspx?ReturnUrl=%2fProject%2fDefault.aspx
我错过了配置步骤吗?