AuthenticatingEventArgs.CustomCredential 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得額外的使用者值進行驗證。
public:
property System::String ^ CustomCredential { System::String ^ get(); };
public string CustomCredential { get; }
member this.CustomCredential : string
Public ReadOnly Property CustomCredential As String
屬性值
驗證需要使用者名稱和密碼以外的值。
範例
下列範例顯示 剖析 屬性中兩個驗證值CustomCredential之 事件的事件處理程式Authenticating。 它會將兩個值和使用者名稱和密碼傳遞至名為 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
備註
您可以使用 CustomCredential 屬性來擷取事件期間 Authenticating 使用者名稱和密碼以外的驗證值。 例如,應用程式可能會設定為驗證標識碼以及使用者名稱和密碼。 在此情況下,標識碼將會在方法的 Login 參數中CustomCredential
傳遞。 然後,您可以透過 CustomCredential 屬性擷取自定義值。
屬性 CustomCredential 包含自定義值,其格式與傳遞給 Login 方法的格式相同。 在事件處理程式中 Authenticating ,如果將多個值儲存在 屬性中,您必須剖析 CustomCredential 屬性值以擷取值。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應