AuthenticationService.Authenticating Event

Occurs when user credentials are being validated.

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

public static event EventHandler<AuthenticatingEventArgs> Authenticating

The Authenticating event is raised when user credentials are being validated. Create an event handler for the Authenticating event to customize how user credentials are validated.

The following example shows how to bind an event handler for the Authenticating event in the Application_Start method of the Global.asax file.

void Application_Start(object sender, EventArgs e) 
{
    System.Web.ApplicationServices.AuthenticationService.Authenticating += 
        new EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs>(AuthenticationService_Authenticating);

}

The following example shows an event handler for the Authenticating event in the Global.asax file. The event handler reads two authentication values from the CustomCredential property and passes them together with 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;
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft