登录控制 - 错误

时间:2009-12-05 17:43:09

标签: asp.net login-control

我的ASP.NET(2.0)页面上有一个Login控件。我像这样处理LoggingIn事件:

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;
     }                
 }

在数据库中找到用户。在此功能结束时,e.Cancel仍然设置为false。但随后出现了LoginError。 LoggedIn没有出现。并且FailureText出现在页面上。我不知道如何调试这个:(

1 个答案:

答案 0 :(得分:1)

您是否也处理过Authenticate事件?

<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