我正在嘗試使用fewtutorials配置身份驗證我在ASP.NET v2.0中的Membership Providers範例中找到了該身份驗證。我已經按照教程中的示例進行了操作,但似乎無法使FormsAuthentication.RedirectFromPage
方法正常工作。當我嘗試登錄時,用戶憑證將通過Membership.ValidateUser
進行驗證,但該頁面將發送回Login.aspx而不是Default.aspx。下面是我的web.config中的相關片段:ASP.NET SqlMembershipProvider無限循環?
...
<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似乎工作得很好),並正在使用的ASP.NET登錄控件我的Login.aspx頁面上的UI。這裏是身份驗證事件處理代碼:
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和「登錄」後,我的網址是:http://localhost/Project/Login.aspx?ReturnUrl=%2fProject%2fDefault.aspx
我錯過配置步驟?
我沒有刪除我以前的答案,因爲它也有效,所以您不需要爲使用ASP.NET成員身份使用Login控件的Authenticate事件編寫任何代碼,但它不是您問題的實際來源。問題出在cookie上。 – 2009-08-19 07:59:25