AuthenticatingEventArgs Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides data for the Authenticating event.
public ref class AuthenticatingEventArgs : EventArgs
public class AuthenticatingEventArgs : EventArgs
type AuthenticatingEventArgs = class
inherit EventArgs
Public Class AuthenticatingEventArgs
Inherits EventArgs
- Inheritance
The following example shows an event handler that passes the UserName and Password values to a custom membership provider to validate the user credentials. The event handler sets Authenticated to the return value of the ValidateUser method and sets AuthenticationIsComplete to true
so that the AuthenticationService class does not validate the credentials.
void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
{
if (e.UserName.IndexOf("@contoso.com") >= 0)
{
e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
}
else if (e.UserName.IndexOf("@fabrikam.com") >= 0)
{
e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
}
else
{
e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
}
e.AuthenticationIsComplete = true;
}
Sub AuthenticationService_Authenticating _
(ByVal sender As Object, _
ByVal e As System.Web.ApplicationServices.AuthenticatingEventArgs)
If (e.Username.IndexOf("@contoso.com") >= 0) Then
e.Authenticated = Membership.Providers("ContosoSqlProvider").ValidateUser(e.Username, e.Password)
ElseIf (e.Username.IndexOf("@fabrikam.com") >= 0) Then
e.Authenticated = Membership.Providers("FabrikamSqlProvider").ValidateUser(e.Username, e.Password)
Else
e.Authenticated = Membership.Provider.ValidateUser(e.Username, e.Password)
End If
e.AuthenticationIsComplete = True
End Sub
You create a handler for the Authenticating event when you want to customize how the user's credentials are authenticated at run time. The AuthenticatingEventArgs class supplies values to any Authenticating event handler. By using the properties available in this class, you can retrieve the user credentials to customize authentication.
The AuthenticationService class raises the Authenticating event before validating the user credentials. The AuthenticationService class constructs an instance of the AuthenticatingEventArgs object and passes it to any Authenticating event handler.
You can use the UserName, Password and CustomCredential properties to retrieve the user credentials. The CustomCredential property can contain additional values that are required for authentication, such as an identification number.
The Authenticated property indicates whether the user credentials are valid. You set the Authenticated property to the result of your customized authentication. In addition, you set the AuthenticationIsComplete property to true
if you have checked the user credentials and do not want the AuthenticationService class to check user credentials through the default membership provider.
Authenticated |
Gets or sets a value that indicates whether the user credentials are valid. |
Authentication |
Gets or sets a value that indicates whether the user credentials have been authenticated. |
Custom |
Gets additional user values for authentication. |
Password |
Gets the password for the user. |
User |
Gets the authentication name for the user. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Product | Versions |
---|---|
.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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: