I have a Login control login1. When an user login his username and password, I want to display error message if something wrong.
By this link, we can easily fire an event by Login1_LoginError. However for some reason, our code always use Login1_Authenticate.
Sample code:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool UserAuthenticated = false;
MembershipProvider AuthenticationProviderUsed = null;
RoleProvider roleProvider = Roles.Providers["SqlRoleProvider"];
MembershipUser user = Membership.GetUser(login1.UserName);
if (user != null && user.IsLockedOut)
{
\\ display error message
}
My question is can I use the code inside the Login1_Authenticate enent? Because it used to be inside Login1_LoginError event.
Thanks.
Login1.FailureText = "Your account has been locked out blah blah.....";
The Login.Authenticate Event will be fired off every time there is an attempt to authenticate; it is where you can provide custom authentication. In this event, you should perform authentication and set
e.Authenticatedtotrueorfalse. Likely, if you set it tofalse, you’ll get to yourLogin1_LoginErrorhandler. However, you can handle the failure to authenticate properly in theLogin1_Authenticatehandler without issue – you do not have to useLogin1_LoginError.