AuthenticationService.Authenticating Événement

Définition

Se produit lorsque les informations d'identification de l'utilisateur sont validées.

public:
 static event EventHandler<System::Web::ApplicationServices::AuthenticatingEventArgs ^> ^ Authenticating;
public static event EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs> Authenticating;
member this.Authenticating : EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs> 
Public Shared Custom Event Authenticating As EventHandler(Of AuthenticatingEventArgs) 

Type d'événement

Exemples

L’exemple suivant montre comment lier un gestionnaire d’événements pour l’événement Authenticating dans la Application_Start méthode du fichier Global.asax.

void Application_Start(object sender, EventArgs e) 
{
    System.Web.ApplicationServices.AuthenticationService.Authenticating += 
        new EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs>(AuthenticationService_Authenticating);

}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler System.Web.ApplicationServices.AuthenticationService.Authenticating, _
      AddressOf Me.AuthenticationService_Authenticating
End Sub

L’exemple suivant montre un gestionnaire d’événements pour l’événement Authenticating dans le fichier Global.asax. Le gestionnaire d’événements lit deux valeurs d’authentification à partir de la CustomCredential propriété et les transmet avec le nom d’utilisateur et le mot de passe à une classe d’authentification personnalisée nommée StudentAuthentication.

void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
{
    string studentid = String.Empty;
    string answer = String.Empty;

    string[] credentials =
        e.CustomCredential.Split(new char[] { ',' });
    if (credentials.Length > 0)
    {
        studentid = credentials[0];
        if (credentials.Length > 1)
        {
            answer = credentials[1];
        }
    }

    try
    {
        e.Authenticated =
            StudentAuthentication.ValidateStudentCredentials
            (e.UserName, e.Password, studentid, answer);
    }
    catch (ArgumentNullException ex)
    {
        e.Authenticated = false;
    }

    e.AuthenticationIsComplete = true;
}
Sub AuthenticationService_Authenticating _
   (ByVal sender As Object, _
    ByVal e As System.Web.ApplicationServices.AuthenticatingEventArgs)
    Dim studentid As String = String.Empty
    Dim answer As String = String.Empty

    Dim credentials As String() = _
         e.CustomCredential.Split(New Char() {","c})
    If (credentials.Length > 0) Then
        studentid = credentials(0)
        If (credentials.Length > 1) Then
            answer = credentials(1)
        End If
    End If

    Try
        e.Authenticated = _
            StudentAuthentication.ValidateStudentCredentials _
            (e.Username, e.Password, studentid, answer)
    Catch ex As ArgumentNullException
        e.Authenticated = False
    End Try
    

    e.AuthenticationIsComplete = True
End Sub

Remarques

L’événement Authenticating est déclenché lorsque les informations d’identification de l’utilisateur sont validées. Créez un gestionnaire d’événements pour l’événement afin de personnaliser la Authenticating façon dont les informations d’identification de l’utilisateur sont validées.

S’applique à

Voir aussi