AuthenticationService.Authenticating 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會在驗證使用者認證時發生。
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)
事件類型
範例
下列範例示範如何在 Global.asax 檔案的 方法中Application_Start
系結 事件的事件處理程式Authenticating。
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
下列範例顯示 Global.asax 檔案中事件的事件處理程式 Authenticating 。 事件處理程式會從 屬性讀取兩個驗證值, CustomCredential 並將其與使用者名稱和密碼一起傳遞至名為的 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
備註
驗證 Authenticating 使用者認證時,就會引發事件。 建立事件的事件處理程式, Authenticating 以自定義使用者認證驗證的方式。