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
屬性值
驗證需要使用者名稱和密碼以外的值。
範例
下列範例顯示事件的事件處理常式 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
備註
您可以使用 CustomCredential 屬性來擷取事件期間 Authenticating 使用者名稱和密碼以外的驗證值。 例如,應用程式可能會設定為將識別碼與使用者名稱和密碼一起驗證。 在此情況下,識別碼將會在 方法的 Login 參數中 CustomCredential
傳遞。 然後,您可以透過 屬性擷 CustomCredential 取自訂值。
屬性 CustomCredential 包含自訂值,格式與傳遞至 Login 方法的格式相同。 Authenticating在事件處理常式中,如果屬性中儲存了多個值,您必須剖析 CustomCredential 屬性值以擷取值。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應