SqlProfileProvider 类

定义

对 ASP.NET 应用程序的配置文件信息在 SQL Server 数据库中的存储进行管理。Manages storage of profile information for an ASP.NET application in a SQL Server database.

public ref class SqlProfileProvider : System::Web::Profile::ProfileProvider
public class SqlProfileProvider : System.Web.Profile.ProfileProvider
type SqlProfileProvider = class
    inherit ProfileProvider
Public Class SqlProfileProvider
Inherits ProfileProvider
继承

示例

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

<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>  
        <clear/>  
        <add name="SqlProvider"   
          type="System.Web.Security.SqlMembershipProvider"   
          connectionStringName="SqlServices"  
          applicationName="SampleApplication"  
          enablePasswordRetrieval="true"  
          enablePasswordReset="true"  
          passwordFormat="Encrypted"  
          requiresQuestionAndAnswer="true" />  
      </providers>  
    </membership>  

    <profile defaultProvider="SqlProvider">  
      <providers>  
        <clear />  
        <add name="SqlProvider"  
          type="System.Web.Profile.SqlProfileProvider"  
          connectionStringName="SqlServices"  
          applicationName="SampleApplication"  
          description="SqlProfileProvider for SampleApplication" />  
      </providers>  

      <properties>  
        <add name="ZipCode" />  
        <add name="CityAndState" />  
      </properties>  
    </profile>  
  </system.web>  
</configuration>  

注解

ASP.NET 配置文件用于存储和检索数据源(如数据库)中的用户设置。The ASP.NET profile is used to store and retrieve user settings in a data source such as a database. 使用当前的属性访问用户配置文件 Profile HttpContextThe user profile is accessed using the Profile property of the current HttpContext. 配置文件信息和属性值使用配置文件提供程序进行管理。Profile information and property values are managed using a profile provider.

SqlProfileProviderASP.NET 使用类来存储和检索使用 SQL Server 数据库的 ASP.NET 应用程序的配置文件设置。The SqlProfileProvider class is used by ASP.NET to store and retrieve profile settings for an ASP.NET application that is using a SQL Server database. 若要使用 SqlProfileProvider ,必须先创建所使用的 SQL Server 数据库 SqlProfileProviderTo use a SqlProfileProvider, you must first create the SQL Server database used by the SqlProfileProvider. 若要创建使用的数据库 SqlProfileProvider ,请运行在 [drive:] \WINDOWS\Microsoft.NET\Framework 文件夹中找到的 aspnet_regsql.exe 工具, \ 2.0versionNumber 并指定 -A p 选项。To create the database used by the SqlProfileProvider, run the aspnet_regsql.exe tool, which is found in the [drive:]\WINDOWS\Microsoft.NET\Framework\2.0versionNumber folder, and specify the -A p option. 以下命令演示了如何使用 aspnet_regsql.exe 可执行文件:The following command demonstrates how you might use the aspnet_regsql.exe executable:

aspnet_regsql.exe -A p  

上面的示例未指定创建的数据库的名称,因此将使用默认名称。The example above does not specify a name for the database that is created, so the default name will be used. 默认数据库名称为 Aspnetdb.mdf。The default database name is Aspnetdb.

计算机配置包含一个 SqlProfileProvider 名为 AspNetSqlProvider 的默认实例,该实例连接到本地计算机上的 SQL Server。The machine configuration contains a default SqlProfileProvider instance named AspNetSqlProvider that connects to the SQL Server on the local machine. 您可以使用此提供程序的实例,或在 ASP.NET 应用程序的 Web.config 文件中指定自己的实例。You can use this instance of the provider, or specify your own in the Web.config file for your ASP.NET application.

备注

如果配置文件提供程序使用集成安全性的连接字符串进行配置,则 ASP.NET 应用程序的进程帐户必须具有连接到 SQL Server 数据库的权限。If the profile 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.

构造函数

SqlProfileProvider()

创建 SqlProfileProvider 类的实例。Creates an instance of the SqlProfileProvider class.

属性

ApplicationName

获取或设置要存储和检索其配置文件信息的应用程序的名称。Gets or sets the name of the application for which to store and retrieve profile information.

Description

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

(继承自 ProviderBase)
Name

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

(继承自 ProviderBase)

方法

DeleteInactiveProfiles(ProfileAuthenticationOption, DateTime)

删除上次活动日期出现在指定日期和时间之前的配置文件的用户配置文件数据。Deletes user profile data for profiles in which the last activity date occurred before the specified date and time.

DeleteProfiles(ProfileInfoCollection)

从数据源中删除提供的一系列配置文件的配置文件属性和信息。Deletes profile properties and information for the supplied list of profiles from the data source.

DeleteProfiles(String[])

从数据源中删除提供的一系列用户名的配置文件属性和信息。Deletes profile properties and information from the data source for the supplied list of user names.

Equals(Object)

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

(继承自 Object)
FindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime, Int32, Int32, Int32)

检索一些配置文件的配置文件信息,在这些配置文件中,上次活动日期与指定的日期和时间相同或在其之前,而且配置文件的用户名与指定的名称匹配。Retrieves profile information for profiles in which the last activity date occurred on or before the specified date and time and the user name for the profile matches the specified name.

FindProfilesByUserName(ProfileAuthenticationOption, String, Int32, Int32, Int32)

检索用户名与指定名称匹配的配置文件的配置文件信息。Retrieves profile information for profiles in which the user name matches the specified name.

GetAllInactiveProfiles(ProfileAuthenticationOption, DateTime, Int32, Int32, Int32)

对于上次活动日期与指定的日期和时间相同或在其之前的配置文件,检索它们的用户配置文件数据。Retrieves user profile data for profiles in which the last activity date occurred on or before the specified date and time.

GetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32)

在数据源中检索配置文件的用户配置文件数据。Retrieves user profile data for profiles in the data source.

GetHashCode()

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

(继承自 Object)
GetNumberOfInactiveProfiles(ProfileAuthenticationOption, DateTime)

获取数据源中上次活动日期与指定的 userInactiveSinceDate 相同或在其之前的配置文件的数量。Gets the number of profiles in the data source where the last activity date occurred on or before the specified userInactiveSinceDate.

GetPropertyValues(SettingsContext, SettingsPropertyCollection)

从 SQL Server 配置文件数据库检索配置文件属性信息和值。Retrieves profile property information and values from a SQL Server profile database.

GetType()

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

(继承自 Object)
Initialize(String, NameValueCollection)

利用在 ASP.NET 应用程序的配置文件中指定的属性值初始化 SQL Server 配置文件提供程序。Initializes the SQL Server profile 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)
SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

利用指定的属性值更新 SQL Server 配置文件数据库。Updates the SQL Server profile database with the specified property values.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于