AuthenticationService.Authenticating Událost

Definice

Vyvolá se při ověřování přihlašovacích údajů uživatele.

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) 

Event Type

Příklady

Následující příklad ukazuje, jak vytvořit vazbu obslužné rutiny události pro Authenticating událost v Application_Start metodě souboru 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

Následující příklad ukazuje obslužnou rutinu Authenticating události v souboru Global.asax. Obslužná rutina události přečte dvě hodnoty ověřování z CustomCredential vlastnosti a předá je společně s uživatelským jménem a heslem do vlastní třídy ověřování s názvem 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

Poznámky

Událost Authenticating se vyvolá při ověřování přihlašovacích údajů uživatele. Vytvořte obslužnou rutinu Authenticating události pro událost, abyste mohli přizpůsobit způsob ověřování přihlašovacích údajů uživatele.

Platí pro

Viz také