Problem with login control
<asp:Login ID="Login1" runat="server"
FailureText="חיבורך לא הייה מוצלח. אנא נסה שנית" LoginButtonText="התחבר"
PasswordLabelText="סיסמה:" PasswordRequiredErrorMessage="יש צורך בסיסמה"
RememberMeText="זכור אותי פעם הבאה" Tit开发者_开发技巧leText="" UserNameLabelText="שם משתמש:"
UserNameRequiredErrorMessage="יש צורך בשם משתמש" Height="100px"
DestinationPageUrl="~/AllQuestions.aspx" PasswordRecoveryText="שכחת סיסמה"
PasswordRecoveryUrl="~/RetrievePassword.aspx" RememberMeSet="True"
onauthenticate="Login1_Authenticate">
<CheckBoxStyle Height="50px" />
<ValidatorTextStyle BorderColor="#CC0000" />
</asp:Login>
The control works only without this part: onauthenticate="Login1_Authenticate"
with that part included, it wont let me login!!!
I dont know why though :(
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (UsefulStaticMethods.CheckIfUserISbanned(Login1.UserName))
{
Server.Transfer("~/Banned.aspx");
}
}
You need to se the Authenticated
flag. MSDN AuthenticateEventArgs
Authenticated:
Gets or sets a value indicating whether a user's authentication attempt succeeded.
You need to add the code:
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;
}
}
If you add a subscriber to the OnAuthenticate event handler, the Login control bypasses its own authentication and turns over full control to the subscriber. You now you have to handle the authentication on your own (which is pretty simple, as shown below)
If you reflect on Login.OnAuthenticate, it looks like this:
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);
}
}
}
精彩评论