ClientFormsAuthenticationMembershipProvider 类

定义

通过客户端应用程序服务实现窗体身份验证。Enables forms authentication with client application services.

public ref class ClientFormsAuthenticationMembershipProvider : System::Web::Security::MembershipProvider
public class ClientFormsAuthenticationMembershipProvider : System.Web.Security.MembershipProvider
type ClientFormsAuthenticationMembershipProvider = class
    inherit MembershipProvider
Public Class ClientFormsAuthenticationMembershipProvider
Inherits MembershipProvider
继承
ClientFormsAuthenticationMembershipProvider

示例

下面的示例代码演示如何使用此方法通过IClientFormsAuthenticationCredentialsProvider实现来验证用户。The following example code demonstrates how to use this method to validate the user by using an IClientFormsAuthenticationCredentialsProvider implementation.

private bool ValidateUsingCredentialsProvider()
{
    bool isAuthorized = false;
    try
    {
        ClientFormsAuthenticationMembershipProvider authProvider =
            System.Web.Security.Membership.Provider as
            ClientFormsAuthenticationMembershipProvider;

        // Call ValidateUser with empty strings in order to display the 
        // login dialog box configured as a credentials provider.
        isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty);
    }
    catch (System.Net.WebException)
    {
        MessageBox.Show("Unable to access the authentication service.",
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    if (!isAuthorized)
    {
        MessageBox.Show("Unable to authenticate.", "Not logged in", 
            MessageBoxButtons.OK, MessageBoxIcon.Error);
        Application.Exit();
    }
    return isAuthorized;
}
Private Function ValidateUsingCredentialsProvider() As Boolean

    Dim isAuthorized As Boolean = False

    Try

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

        ' Call ValidateUser with empty strings in order to display the 
        ' login dialog box configured as a credentials provider.
        isAuthorized = authProvider.ValidateUser(String.Empty, String.Empty)

    Catch ex As System.Net.WebException

        MessageBox.Show("Unable to access the authentication service.", _
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End Try

    If Not isAuthorized Then

        MessageBox.Show("Unable to authenticate.", "Not logged in", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        Application.Exit()

    End If

    Return isAuthorized

End Function

注解

可以使用客户端应用程序服务通过 forms 身份验证来验证用户。You can use client application services to validate users by using forms authentication. 若要启用表单身份验证,请将应用程序配置ClientFormsAuthenticationMembershipProvider为使用类。To enable forms authentication, you configure your application to use the ClientFormsAuthenticationMembershipProvider class. 有关详细信息,请参阅如何:配置客户端应用程序服务For more information, see How to: Configure Client Application Services.

配置后,可以通过调用static Membership.ValidateUser方法来验证用户ClientFormsAuthenticationMembershipProvider.ValidateUser(String, String) ,该方法在内部调用方法。After configuration, you can validate users by calling the static Membership.ValidateUser method, which internally calls the ClientFormsAuthenticationMembershipProvider.ValidateUser(String, String) method.

Forms 身份验证要求用户通过应用程序提供的登录控件指定其凭据。Forms authentication requires that the user specify their credentials through login controls provided by your application. 可以检索凭据并将其传递给Membership.ValidateUser方法。You can retrieve the credentials and pass them to the Membership.ValidateUser method. 你还可以传递空字符串或null使用凭据提供程序。You can also pass in empty strings or null to use a credentials provider. 凭据提供程序是在IClientFormsAuthenticationCredentialsProvider应用程序配置文件中指定的实现。A credentials provider is an IClientFormsAuthenticationCredentialsProvider implementation specified in your application configuration file. 通常会实现IClientFormsAuthenticationCredentialsProvider.GetCredentials方法以显示登录对话框并返回填充ClientFormsAuthenticationCredentials的对象。You will typically implement the IClientFormsAuthenticationCredentialsProvider.GetCredentials method to display a login dialog box and return a populated ClientFormsAuthenticationCredentials object. 使用凭据提供程序,让你可以在多个应用程序间共享单点登录对话框。Using a credentials provider enables you to share a single login dialog box among multiple applications.

方法通过ServiceUri属性指示的登录服务对用户进行身份验证。 ClientFormsAuthenticationMembershipProvider.ValidateUserThe ClientFormsAuthenticationMembershipProvider.ValidateUser method authenticates users through the login service indicated by the ServiceUri property. 通常,从应用ServiceUri程序配置文件和其他配置值检索属性的值。The value of the ServiceUri property is typically retrieved from the application configuration file along with other configuration values. 有关详细信息,请参阅如何:配置客户端应用程序服务For more information, see How to: Configure Client Application Services.

如果用户成功通过身份验证,则服务提供程序将static Thread.CurrentPrincipal属性设置为新ClientRolePrincipal的对象,该对象ClientFormsIdentity包含包含用户信息的新对象。If the user is successfully authenticated, the service provider sets the static Thread.CurrentPrincipal property to a new ClientRolePrincipal object that contains a new ClientFormsIdentity object that contains the user information. 如果为ClientRoleProvider应用程序配置了,则可以ClientRolePrincipal使用对象从角色服务中检索用户角色信息。If a ClientRoleProvider is configured for your application, you can use the ClientRolePrincipal object to retrieve user role information from the roles service.

您可以ClientFormsAuthenticationMembershipProvider static 通过属性检索对当前Membership.Provider实例的引用。You can retrieve a reference to the current ClientFormsAuthenticationMembershipProvider instance through the static Membership.Provider property. 您可以使用成员资格提供程序引用直接调用ClientFormsAuthenticationMembershipProvider.ValidateUser方法。You can use the membership provider reference to call the ClientFormsAuthenticationMembershipProvider.ValidateUser method directly. 此外,还需要成员资格提供程序引用来调用Logout方法,该方法MembershipProvider在基类中不可用。Additionally, you will need the membership provider reference to call the Logout method, which is not available in the MembershipProvider base class.

不能使用ClientFormsAuthenticationMembershipProvider类创建、删除或修改成员身份信息。You cannot use the ClientFormsAuthenticationMembershipProvider class to create, delete, or modify membership information. 若要创建、删除或修改用户,必须更改服务器上登录服务的配置。To create, delete, or modify users, you must change the configuration of the login service on the server.

构造函数

ClientFormsAuthenticationMembershipProvider()

初始化 ClientFormsAuthenticationMembershipProvider 类的新实例。Initializes a new instance of the ClientFormsAuthenticationMembershipProvider class.

属性

ApplicationName

此类未使用此属性。This property is not used by this class.

Description

获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)
EnablePasswordReset

此类未使用此属性。This property is not used by this class.

EnablePasswordRetrieval

此类未使用此属性。This property is not used by this class.

MaxInvalidPasswordAttempts

此类未使用此属性。This property is not used by this class.

MinRequiredNonAlphanumericCharacters

此类未使用此属性。This property is not used by this class.

MinRequiredPasswordLength

此类未使用此属性。This property is not used by this class.

Name

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)
PasswordAttemptWindow

此类未使用此属性。This property is not used by this class.

PasswordFormat

此类未使用此属性。This property is not used by this class.

PasswordStrengthRegularExpression

此类未使用此属性。This property is not used by this class.

RequiresQuestionAndAnswer

此类未使用此属性。This property is not used by this class.

RequiresUniqueEmail

此类未使用此属性。This property is not used by this class.

ServiceUri

获取或设置身份验证服务的 URI。Gets or sets the URI of the authentication service.

方法

ChangePassword(String, String, String)

此类未使用此方法。This method is not used by this class.

ChangePasswordQuestionAndAnswer(String, String, String, String)

此类未使用此方法。This method is not used by this class.

CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

此类未使用此方法。This method is not used by this class.

DecryptPassword(Byte[])

解密已加密的密码。Decrypts an encrypted password.

(继承自 MembershipProvider)
DeleteUser(String, Boolean)

此类未使用此方法。This method is not used by this class.

EncryptPassword(Byte[])

对密码进行加密。Encrypts a password.

(继承自 MembershipProvider)
EncryptPassword(Byte[], MembershipPasswordCompatibilityMode)

使用指定的密码兼容性模式对指定密码进行加密。Encrypts the specified password using the specified password-compatibility mode.

(继承自 MembershipProvider)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindUsersByEmail(String, Int32, Int32, Int32)

此类未使用此方法。This method is not used by this class.

FindUsersByName(String, Int32, Int32, Int32)

此类未使用此方法。This method is not used by this class.

GetAllUsers(Int32, Int32, Int32)

此类未使用此方法。This method is not used by this class.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetNumberOfUsersOnline()

此类未使用此方法。This method is not used by this class.

GetPassword(String, String)

此类未使用此方法。This method is not used by this class.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetUser(Object, Boolean)

此类未使用此方法。This method is not used by this class.

GetUser(String, Boolean)

此类未使用此方法。This method is not used by this class.

GetUserNameByEmail(String)

此类未使用此方法。This method is not used by this class.

Initialize(String, NameValueCollection)

初始化提供程序。Initializes the provider.

Logout()

注销用户。Logs out the user.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
OnValidatingPassword(ValidatePasswordEventArgs)

如果定义了事件处理程序,则引发 ValidatingPassword 事件。Raises the ValidatingPassword event if an event handler has been defined.

(继承自 MembershipProvider)
ResetPassword(String, String)

此类未使用此方法。This method is not used by this class.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
UnlockUser(String)

此类未使用此方法。This method is not used by this class.

UpdateUser(MembershipUser)

此类未使用此方法。This method is not used by this class.

ValidateUser(String, String)

使用指定的用户名和密码对用户进行身份验证。Authenticates a user by using the specified user name and password.

ValidateUser(String, String, Boolean)

使用指定的用户名和密码对用户进行身份验证,并可以选择将密码的哈希值存储在本地数据缓存中。Authenticates a user by using the specified user name and password, optionally storing a hash of the password in the local data cache.

ValidateUser(String, String, String)

使用指定的用户名和密码对位于指定服务 URI 处的用户进行身份验证。Authenticates a user at the specified service URI by using the specified user name and password.

事件

UserValidated

在用户通过验证后发生。Occurs when the user is validated.

ValidatingPassword

在创建用户、更改密码或重置密码时发生。Occurs when a user is created, a password is changed, or a password is reset.

(继承自 MembershipProvider)

适用于

另请参阅