共用方式為


AuthenticatingEventArgs.CustomCredential 屬性

定義

取得額外的使用者值進行驗證。

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 屬性值以擷取值。

適用於

另請參閱