Login.OnLoginError(EventArgs) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Déclenche l’événement LoginError en cas d’échec d’une tentative de connexion.
protected:
virtual void OnLoginError(EventArgs ^ e);
protected virtual void OnLoginError(EventArgs e);
abstract member OnLoginError : EventArgs -> unit
override this.OnLoginError : EventArgs -> unit
Protected Overridable Sub OnLoginError (e As EventArgs)
Paramètres
Exemples
L’exemple de code suivant utilise l’événement LoginError pour afficher les liens d’aide vers l’utilisateur lorsqu’une tentative de connexion échoue.
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
// This custom Login control displays help
// information if the user does not log in
// on the first attempt.
class CustomLogin : Login
{
override protected void OnLoginError(EventArgs e)
{
HelpPageText = "Help with logging in...";
CreateUserText = "Create a new user...";
PasswordRecoveryText = "Forgot your password?";
}
public CustomLogin()
{
CreateUserUrl = "createUser.aspx";
HelpPageUrl = "loginHelp.aspx";
PasswordRecoveryUrl = "getPass.aspx";
}
}
// Add the custom login control to the page.
void Page_Load(object sender, EventArgs e)
{
CustomLogin loginControl = new CustomLogin();
loginControl.ID = "loginControl";
Placeholder1.Controls.Add(loginControl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:placeholder id="Placeholder1" runat="server"></asp:placeholder>
</form>
</body>
</html>
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' This custom Login control displays help
' informatin if the user does not log in
' on the first attempt.
Class CustomLogin
Inherits Login
Protected Overrides Sub OnLoginError(ByVal e As EventArgs)
HelpPageText = "Help with logging in..."
CreateUserText = "Create a new user..."
PasswordRecoveryText = "Forgot your password?"
End Sub
Sub New()
CreateUserUrl = "createUser.aspx"
HelpPageUrl = "loginHelp.aspx"
PasswordRecoveryUrl = "getPass.aspx"
End Sub
End Class
' Add the custom login control to the page.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim loginControl As New CustomLogin
loginControl.ID = "loginControl"
PlaceHolder1.Controls.Add(loginControl)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:placeholder id="Placeholder1" runat="Server"></asp:placeholder>
</form>
</body>
</html>
Remarques
La OnLoginError méthode déclenche l’événement LoginError . Utilisez l’événement LoginError pour fournir un traitement supplémentaire, tel que la journalisation des erreurs, lorsque la tentative de connexion d’un utilisateur échoue.
Le déclenchement d’un événement appelle le gestionnaire d’événements par le biais d’un délégué. Pour plus d’informations, consultez Gestion et déclenchement d’événements.
La OnLoginError méthode permet également aux classes dérivées de gérer l’événement sans attacher de délégué. Il s’agit de la technique recommandée pour gérer l’événement dans une classe dérivée.
Notes pour les héritiers
En cas de OnLoginError(EventArgs) substitution dans une classe dérivée, veillez à appeler la méthode de la classe de OnLoginError(EventArgs) base afin que les délégués inscrits reçoivent l’événement.