Rediger

Del via


ClientWindowsAuthenticationMembershipProvider.ValidateUser Method

Definition

Automatically authenticates the current user by using the identity supplied by the operating system.

public:
 override bool ValidateUser(System::String ^ username, System::String ^ password);
public override bool ValidateUser (string username, string password);
override this.ValidateUser : string * string -> bool
Public Overrides Function ValidateUser (username As String, password As String) As Boolean

Parameters

username
String

Must be Empty or null.

password
String

Must be Empty or null.

Returns

Always true.

Exceptions

username is not Empty or null.

-or-

password is not Empty or null.

Examples

The following example code demonstrates how to use this method to authenticate a user by using Windows authentication.

private bool ValidateUsingWindowsAuthentication()
{
    ClientWindowsAuthenticationMembershipProvider authProvider =
        System.Web.Security.Membership.Provider as
        ClientWindowsAuthenticationMembershipProvider;

    // Call ValidateUser and pass null values for the parameters.
    // This call always returns true.
    return authProvider.ValidateUser(null, null);
}
Private Function ValidateUsingWindowsAuthentication() As Boolean

    Dim authProvider As ClientWindowsAuthenticationMembershipProvider = _
        CType(System.Web.Security.Membership.Provider,  _
        ClientWindowsAuthenticationMembershipProvider)

    ' Call ValidateUser and pass Nothing for the parameters.
    ' This call always returns true.
    Return authProvider.ValidateUser(Nothing, Nothing)

End Function

Remarks

When you configure your application to use the ClientWindowsAuthenticationMembershipProvider class, the static Membership.ValidateUser method will use this method for its implementation. The ClientWindowsAuthenticationMembershipProvider.ValidateUser method automatically authenticates the current user and sets the static Thread.CurrentPrincipal property to a ClientRolePrincipal object that contains the current WindowsIdentity. If a ClientRoleProvider is configured for your application, you can use the ClientRolePrincipal object to retrieve user role information from the roles service.

Applies to

See also