2011-07-12 134 views
1
<asp:Login ID="Login1" runat="server" 
     FailureText="חיבורך לא הייה מוצלח. אנא נסה שנית" LoginButtonText="התחבר" 
     PasswordLabelText="סיסמה:" PasswordRequiredErrorMessage="יש צורך בסיסמה" 
     RememberMeText="זכור אותי פעם הבאה" TitleText="" UserNameLabelText="שם משתמש:" 
     UserNameRequiredErrorMessage="יש צורך בשם משתמש" Height="100px" 
     DestinationPageUrl="~/AllQuestions.aspx" PasswordRecoveryText="שכחת סיסמה" 
     PasswordRecoveryUrl="~/RetrievePassword.aspx" RememberMeSet="True" 
     onauthenticate="Login1_Authenticate"> 

    <CheckBoxStyle Height="50px" /> 
    <ValidatorTextStyle BorderColor="#CC0000" /> 
</asp:Login> 

該控件僅在沒有此部分的情況下工作:onauthenticate="Login1_Authenticate"包含該部分,它不會讓我登錄!登錄控制問題

我不知道爲什麼,雖然:(

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) 
{ 

    if (UsefulStaticMethods.CheckIfUserISbanned(Login1.UserName)) 
    { 
     Server.Transfer("~/Banned.aspx"); 
    } 
} 
+2

這是怎麼回事?錯誤?沒有? – Nix

+1

當你調試代碼到達了嗎?並且CheckIfUserISbanned的行爲是否正確?或者如果你得到和錯誤是什麼? – Dave

+0

正如我所說...沒有錯誤...默認消息出現:「你不能登錄,再試一次」 –

回答

2

您需要瑟的Authenticated標誌MSDN AuthenticateEventArgs

認證方式:

獲取或設置一個值,指示是否一個用戶的身份驗證嘗試成功

您需要添加代碼:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e){ 
    if (UsefulStaticMethods.CheckIfUserISbanned(Login1.UserName)) { 
     e.Authenticated = false; 
     Server.Transfer("~/Banned.aspx"); 
    }else{ 
     //authenticate... 
     e.Authenticated = true; 
    } 
} 
+0

感謝它的工作..我被困在這個4小時。現在它運行得很好..爲什麼現在它工作? –

+0

如果您閱讀我發送的鏈接說:「Web站點的自定義身份驗證方案使用Authenticated屬性來指示用戶的登錄嘗試是否成功。」您需要告訴asp您已驗證了此人的憑據。 *用戶通過身份驗證後,您是否嘗試做某些事情? – Nix

+0

只將他重定​​向到主頁..但它確實將他重定向到主頁 –

0

如果添加一個用戶到OnAuthenticate事件處理程序,登錄控制繞過自己的身份驗證和原來的完全控制給用戶。現在,你必須處理驗證你自己(這是非常簡單的,如下圖所示)

如果你反省Login.OnAuthenticate,它看起來像這樣:

namespace System.Web.UI.WebControls 
{ 
    public class Login : CompositeControl 
    { 
     // other code omitted 

     protected virtual void OnAuthenticate(AuthenticateEventArgs e) 
     { 
      AuthenticateEventHandler handler = this.Authenticate; 

      if (handler != null) 
       handler(this, e); 
      else 
       this.AuthenticateUsingMembershipProvider(e); 
     } 

     private void AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) 
     { 
      var provider = LoginUtil.GetProvider(this.MembershipProvider); 
      e.Authenticated = provider.ValidateUser(
        this.UserNameInternal, this.PasswordInternal); 
     } 
    } 
}