AuthenticatingEventArgs.Authenticated 属性

定义

获取或设置一个值,该值指示用户凭据是否有效。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

属性值

Boolean

如果用户凭据有效,则为 true;否则为 falsetrue if the user credentials are valid; otherwise, false.

示例

下面的示例演示了一个事件处理程序,它将 UserNamePassword 值传递到自定义成员资格提供程序以验证用户凭据。The following example shows an event handler that passes UserName and Password values to a custom membership provider to validate the user credentials. 事件处理程序将设置 Authenticated 为方法的返回值 ValidateUser ,并将设置 AuthenticationIsComplete 为, true 以使 AuthenticationService 类不验证凭据。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

注解

如果在事件的事件处理程序中对用户凭据进行身份验证 Authenticating ,请设置 Authenticated 属性以指示用户凭据是否有效。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. 如果用户凭据有效并且不需要其他验证,则将设置 AuthenticatedtrueAuthenticationIsComplete trueIf the user credentials are valid and no additional validation is needed, set Authenticated to true and AuthenticationIsComplete to true. 设置 AuthenticationIsComplete 属性以指示身份验证服务应跳过用于对用户进行身份验证的默认步骤。You set the AuthenticationIsComplete property to indicate that the authentication service should bypass the default steps for authenticating a user. Authenticated AuthenticationService 仅当设置为时,类才使用中的值 AuthenticationIsComplete trueThe value in Authenticated is used by the AuthenticationService class only if AuthenticationIsComplete is set to true. 如果 AuthenticationIsCompletefalse ,则 AuthenticationService 类将调用默认的成员资格提供程序来验证用户凭据,然后覆盖中的值 AuthenticatedIf AuthenticationIsComplete is false, the AuthenticationService class calls the default membership provider to validate user credentials, and then overwrites the value in Authenticated.

适用于