AuthenticationService.Authenticating Event

Definition

Occurs when user credentials are being validated.

C#
public static event EventHandler<System.Web.ApplicationServices.AuthenticatingEventArgs> Authenticating;

Event Type

Examples

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

C#
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.

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

Remarks

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.

Applies to

Produkt Verzie
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also