Контроль входа в систему - ошибка
-
13-09-2019 - |
Вопрос
На моей странице есть элемент управления входом в систему ASP.NET (2.0).Я обрабатываю событие 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.Но затем произошла ошибка входа в систему.Вход в систему не произошел.И на странице появится FailureText.Я не знаю, как это отладить:(
Решение
Справлялись ли вы также с 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.
}
Не связан с StackOverflow