Partilhar via


AuthenticationService.Authenticating Evento

Definição

Ocorre quando as credenciais do usuário estão sendo validadas.

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) 

Tipo de evento

Exemplos

O exemplo a seguir mostra como associar um manipulador de eventos para o Authenticating evento no Application_Start método do arquivo 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

O exemplo a seguir mostra um manipulador de eventos para o Authenticating evento no arquivo Global.asax. O manipulador de eventos lê dois valores de autenticação da CustomCredential propriedade e os passa junto com o nome de usuário e a senha para uma classe de autenticação personalizada chamada 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

Comentários

O Authenticating evento é gerado quando as credenciais do usuário estão sendo validadas. Crie um manipulador de eventos para o Authenticating evento para personalizar como as credenciais do usuário são validadas.

Aplica-se a

Confira também