views:

171

answers:

1

Hello everybody! There is a Login control on my ASP.NET (2.0) page. I handle LoggingIn event like this:

protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{

    // go to database and find this user

    if (userTable != null && userTable.Rows.Count > 0)
    {
        int userID = Convert.ToInt32(userTable.Rows[0]["UserID"]);

        HttpCookie userIdCookie = new HttpCookie("UserID", userID.ToString());
        Response.AppendCookie(userIdCookie);

     }
     else
     {
         e.Cancel = true;
     }                
 }

User found in database. And at the end of this function e.Cancel still set to false. But then occured LoginError. LoggedIn doesn't occured. And FailureText appears on the page. I don't know how to debug this :(

+1  A: 

Have you also handled the Authenticate event?

<asp:Login id="Login1" runat="server"
            OnAuthenticate="MyOnAuthenticate">


private void MyOnAuthenticate(object sender, AuthenticateEventArgs e)
{
    bool isAuthenticated = false;
    isAuthenticated = YourAuthenticationMethod(Login1.UserName, Login1.Password);

    e.Authenticated = isAuthenticated;
}

private bool YourAuthenticationMethod(string UserName, string pwd)
{
    // Insert code that implements a site-specific custom 
    // authentication method here.             
}

LoginControl's Authenticated event on MSDN

p.campbell