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

        e.Authenticated =
            (e.UserName, e.Password, studentid, answer);
    catch (ArgumentNullException ex)
        e.Authenticated = false;

    e.AuthenticationIsComplete = true;

.NET Framework
Available since 3.5
Return to top