Share via


ClientWindowsAuthenticationMembershipProvider.ValidateUser 方法

定義

使用作業系統所提供的識別自動驗證目前使用者。

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

參數

username
String

必須是 Emptynull

password
String

必須是 Emptynull

傳回

一定是 true

例外狀況

username 不是 Emptynull

-或-

password 不是 Emptynull

範例

下列範例程式碼示範如何使用這個方法來使用 Windows 驗證 來驗證使用者。

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

備註

當您將應用程式設定為使用 ClientWindowsAuthenticationMembershipProvider 類別時, staticMembership.ValidateUser 方法會使用這個方法進行實作。 方法 ClientWindowsAuthenticationMembershipProvider.ValidateUser 會自動驗證目前的使用者,並將 屬性設定 staticThread.CurrentPrincipalClientRolePrincipal 包含目前 WindowsIdentity 的 物件。 ClientRoleProvider如果 已為您的應用程式設定 ,您可以使用 ClientRolePrincipal 物件從角色服務擷取使用者角色資訊。

適用於

另請參閱