AuthenticationService.Authenticating Zdarzenie
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Występuje, gdy poświadczenia użytkownika są weryfikowane.
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)
Typ zdarzenia
Przykłady
W poniższym przykładzie pokazano, jak powiązać program obsługi zdarzeń dla Authenticating zdarzenia w Application_Start
metodzie pliku 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
Poniższy przykład przedstawia procedurę obsługi zdarzeń dla Authenticating zdarzenia w pliku Global.asax. Procedura obsługi zdarzeń odczytuje dwie wartości uwierzytelniania z CustomCredential właściwości i przekazuje je wraz z nazwą użytkownika i hasłem do niestandardowej klasy uwierzytelniania o nazwie 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
Uwagi
Zdarzenie Authenticating jest zgłaszane, gdy poświadczenia użytkownika są weryfikowane. Utwórz procedurę obsługi zdarzeń dla Authenticating zdarzenia, aby dostosować sposób weryfikacji poświadczeń użytkownika.
Dotyczy
Zobacz też
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla