AuthenticatingEventArgs.CustomCredential 属性

定义

获取用于身份验证的其他用户值。

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 才能检索值。

适用于

另请参阅