Edit

Share via


AuthenticatingEventArgs.CustomCredential Property

Definition

Gets additional user values for authentication.

public:
 property System::String ^ CustomCredential { System::String ^ get(); };
public string CustomCredential { get; }
member this.CustomCredential : string
Public ReadOnly Property CustomCredential As String

Property Value

The values required for authentication other than user name and password.

Examples

The following example shows an event handler for the Authenticating event that parses two authentication values from the CustomCredential property. It passes the two values and the user name and password to a custom authentication class named 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

Remarks

You can use the CustomCredential property to retrieve authentication values other than user name and password during the Authenticating event. For example, an application might be configured to validate an identification number together with the user name and password. In that case, the identification number will be passed in the CustomCredential parameter of the Login method. You can then retrieve the custom value through the CustomCredential property.

The CustomCredential property contains the customized values in the same format as they are passed to the Login method. In the Authenticating event handler, if more than one value is stored in the property, you must parse the value of the CustomCredential property to retrieve the values.

Applies to

See also