Export (0) Print
Expand All

AuthenticatingEventArgs.CustomCredential Property

Gets additional user values for authentication.

Namespace:  System.Web.ApplicationServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public string CustomCredential { get; }

Property Value

Type: System.String
The values required for authentication other than user name and password.

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.

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;
}


.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft