SqlMembershipProvider 类

定义

管理 SQL Server 数据库中 ASP.NET 应用程序的成员资格信息存储。Manages storage of membership information for an ASP.NET application in a SQL Server database.

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

示例

下面的代码示例显示了配置为使用的SqlMembershipProviderASP.NET 应用程序的 web.config 文件。The following code example shows the Web.config file for an ASP.NET application configured to use a SqlMembershipProvider.

<configuration>  
  <connectionStrings>  
    <add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />  
  </connectionStrings>  
  <system.web>  
    <authentication mode="Forms" >  
      <forms loginUrl="login.aspx"  
        name=".ASPXFORMSAUTH" />  
    </authentication>  
    <authorization>  
      <deny users="?" />  
    </authorization>  
    <membership defaultProvider="SqlProvider"  
      userIsOnlineTimeWindow="15">  
      <providers>  
        <add   
          name="SqlProvider"   
          type="System.Web.Security.SqlMembershipProvider"   
          connectionStringName="SqlServices"  
          applicationName="MyApplication"  
          enablePasswordRetrieval="false"  
          enablePasswordReset="true"  
          requiresQuestionAndAnswer="true"  
          requiresUniqueEmail="false"  
          passwordFormat="Hashed"  
          maxInvalidPasswordAttempts="5"  
          passwordAttemptWindow="10" />  
      </providers>  
    </membership>  
  </system.web>  
</configuration>  

注解

MembershipMembershipUser类使用此类为使用 SQL Server 数据库的 ASP.NET 应用程序提供成员身份服务。This class is used by the Membership and MembershipUser classes to provide membership services for an ASP.NET application using a SQL Server database. 不能使用不SqlMembershipProvider带 SQL Server 的。You cannot use a SqlMembershipProvider without SQL Server. 如果计算机安装了默认实例名称和用户实例化的 SQL Server Express,则在第一SqlMembershipProvider次应用程序时,对象aspnetdb将在应用程序App_Data的目录中创建一个名为的数据库。运行。When your computer has SQL Server Express installed with the default instance name and user-instancing enabled, the SqlMembershipProvider object will create a database called aspnetdb in the application's App_Data directory the first time the application is run.

若要手动创建数据库,请运行Aspnet_regsql.exe %systemroot%\Microsoft.NET\Framework\ versionNumber在文件夹中找到的可执行文件-A m并指定选项( aspnet_regsql.exe -A m例如)。To manually create the database, run the Aspnet_regsql.exe executable found in the %systemroot%\Microsoft.NET\Framework\ versionNumber folder and specify the -A m option (for example aspnet_regsql.exe -A m). 创建的数据库名为 Aspnetdb.mdf。The database created is called Aspnetdb. 或者,运行Aspnet_regsql.exe以提取 GUI 配置模式并选择配置所有 ASP.NET 功能。Alternatively, run Aspnet_regsql.exe to pull up the GUI configuration mode and choose to configure all ASP.NET Features.

如果成员资格提供程序配置了使用集成安全性的连接字符串,则 ASP.NET 应用程序的进程帐户必须具有连接到 SQL Server 数据库的权限。If the membership provider is configured with a connection string that uses integrated security, the process account of the ASP.NET application must have rights to connect to the SQL Server database.

Machine.config 文件定义一个名为SqlMembershipProvider AspNetSqlMembershipProvider的默认实例,该实例连接到本地计算机上的默认 SQL Server Express 实例。The Machine.config file defines a default SqlMembershipProvider instance named AspNetSqlMembershipProvider that connects to the default SQL Server Express instance on the local machine. 如果使用默认实例名称安装 SQL Server Express,则可以使用此提供程序的实例,也可以在 ASP.NET 应用程序的 web.config 文件中定义自己的实例。You can use this instance of the provider if you installed SQL Server Express with the default instance name, or you can define your own instance in the Web.config file for your ASP.NET application.

如果将passwordCompatMode属性设置为Framework40,则应用程序可以使用 ASP.NET 4 中已添加的哈希和加密成员资格选项。If you set the passwordCompatMode attribute to Framework40, the application can use the hashing and encryption membership options that were added in ASP.NET 4. 但是,如果passwordCompatMode将属性设置为Framework20,则只能使用 ASP.NET 2.0、ASP.NET 3.5 和 ASP.NET 3.5 SP1 中的哈希和加密成员资格选项。However, if the passwordCompatMode attribute is set to Framework20, only the hashing and encryption membership options from the ASP.NET 2.0, ASP.NET 3.5, and ASP.NET 3.5 SP1 can be used. 默认值为 Framework20The default value is Framework20. 有关详细信息,请参阅 MembershipPasswordCompatibilityModeFor more information, see MembershipPasswordCompatibilityMode.

构造函数

SqlMembershipProvider()

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

属性

ApplicationName

获取或设置要存储和检索其成员资格信息的应用程序的名称。Gets or sets the name of the application to store and retrieve membership information for.

Description

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

(继承自 ProviderBase)
EnablePasswordReset

获取一个值,指示 SQL Server 成员资格提供程序是否配置为允许用户重置其密码。Gets a value indicating whether the SQL Server membership provider is configured to allow users to reset their passwords.

EnablePasswordRetrieval

获取一个值,指示 SQL Server 成员资格提供程序是否配置为允许用户检索其密码。Gets a value indicating whether the SQL Server membership provider is configured to allow users to retrieve their passwords.

MaxInvalidPasswordAttempts

获取锁定成员资格用户前允许的无效密码或无效密码提示问题答案尝试次数。Gets the number of invalid password or password-answer attempts allowed before the membership user is locked out.

MinRequiredNonAlphanumericCharacters

获取有效密码中必须包含的最少特殊字符数。Gets the minimum number of special characters that must be present in a valid password.

MinRequiredPasswordLength

获取密码所要求的最小长度。Gets the minimum length required for a password.

Name

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

(继承自 ProviderBase)
PasswordAttemptWindow

获取时间长度,在该时间间隔内对提供有效密码或密码答案的连续失败尝试次数进行跟踪。Gets the time window between which consecutive failed attempts to provide a valid password or password answers are tracked.

PasswordFormat

获取一个值,该值指示 SQL Server 成员资格数据库中存储密码的格式。Gets a value indicating the format for storing passwords in the SQL Server membership database.

PasswordStrengthRegularExpression

获取用于计算密码的正则表达式。Gets the regular expression used to evaluate a password.

RequiresQuestionAndAnswer

获取一个值,指示 SQL Server 成员资格提供程序是否配置为要求用户在进行密码重置和检索时回答密码提示问题。Gets a value indicating whether the SQL Server membership provider is configured to require the user to answer a password question for password reset and retrieval.

RequiresUniqueEmail

获取一个值,指示 SQL Server 成员资格提供程序是否配置为要求每个用户名具有唯一的电子邮件地址。Gets a value indicating whether the SQL Server membership provider is configured to require a unique email address for each user name.

方法

ChangePassword(String, String, String)

修改用户密码。Modifies a user's password.

ChangePasswordQuestionAndAnswer(String, String, String, String)

更新 SQL Server 成员资格数据库中用户的密码提示问题和答案。Updates the password question and answer for a user in the SQL Server membership database.

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

向 SQL Server 成员资格数据库添加一个新用户。Adds a new user to the SQL Server membership database.

DecryptPassword(Byte[])

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

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

从 SQL Server 成员资格数据库删除用户的成员资格信息。Removes a user's membership information from the SQL Server membership database.

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)

返回成员资格用户集合,这些用户的电子邮件地址字段包含指定的电子邮件地址。Returns a collection of membership users for which the email address field contains the specified email address.

FindUsersByName(String, Int32, Int32, Int32)

获取一个成员资格用户的集合,其中的用户名包含要匹配的指定用户名。Gets a collection of membership users where the user name contains the specified user name to match.

GeneratePassword()

生成长度至少为 14 个字符的随机密码。Generates a random password that is at least 14 characters long.

GetAllUsers(Int32, Int32, Int32)

获取 SQL Server 成员资格数据库中所有用户的集合。Gets a collection of all the users in the SQL Server membership database.

GetHashCode()

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

(继承自 Object)
GetNumberOfUsersOnline()

返回当前访问该应用程序的用户数。Returns the number of users currently accessing the application.

GetPassword(String, String)

从 SQL Server 成员资格数据库返回指定用户名的密码。Returns the password for the specified user name from the SQL Server membership database.

GetType()

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

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

从数据源获得与指定的唯一标识符关联的成员资格用户的信息,并更新该用户的上次活动日期/时间戳(如果指定)。Gets the information from the data source for the membership user associated with the specified unique identifier and updates the last activity date/time stamp for the user, if specified.

GetUser(String, Boolean)

从 SQL Server 成员资格数据库返回用户的信息,并提供更新用户的上次活动日期/时间戳的可选功能。Returns information from the SQL Server membership database for a user and provides an option to update the last activity date/time stamp for the user.

GetUserNameByEmail(String)

获取与指定电子邮件地址关联的用户名。Gets the user name associated with the specified email address.

Initialize(String, NameValueCollection)

使用 ASP.NET 应用程序配置文件中指定的属性值初始化 SQL Server 成员资格提供程序。Initializes the SQL Server membership provider with the property values specified in the ASP.NET application's configuration file. 此方法不能直接在代码中使用。This method is not intended to be used directly from your code.

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)

将用户密码重置为一个自动生成的新密码。Resets a user's password to a new, automatically generated password.

ToString()

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

(继承自 Object)
UnlockUser(String)

清除用户的锁定状态,以便可以验证该成员资格用户。Clears the user's locked-out status so that the membership user can be validated.

UpdateUser(MembershipUser)

更新 SQL Server 成员资格数据库中用户的信息。Updates information about a user in the SQL Server membership database.

ValidateUser(String, String)

验证 SQL Server 成员资格数据库中是否存在指定的用户名和密码。Verifies that the specified user name and password exist in the SQL Server membership database.

事件

ValidatingPassword

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

(继承自 MembershipProvider)

适用于

另请参阅