Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.