Rediger

Del via


AuthenticatingEventArgs.Authenticated Property

Definition

Gets or sets a value that indicates whether the user credentials are valid.

public:
 property bool Authenticated { bool get(); void set(bool value); };
public bool Authenticated { get; set; }
member this.Authenticated : bool with get, set
Public Property Authenticated As Boolean

Property Value

true if the user credentials are valid; otherwise, false.

Examples

The following example shows an event handler that passes 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

Remarks

If you authenticate user credentials in an event handler for the Authenticating event, set the Authenticated property to indicate whether the user credentials are valid. If the user credentials are valid and no additional validation is needed, set Authenticated to true and AuthenticationIsComplete to true. You set the AuthenticationIsComplete property to indicate that the authentication service should bypass the default steps for authenticating a user. The value in Authenticated is used by the AuthenticationService class only if AuthenticationIsComplete is set to true. If AuthenticationIsComplete is false, the AuthenticationService class calls the default membership provider to validate user credentials, and then overwrites the value in Authenticated.

Applies to

See also