SqlProfileProvider 类

定义

对 ASP.NET 应用程序的配置文件信息在 SQL Server 数据库中的存储进行管理。

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
继承

示例

下面的代码示例演示配置为使用 a SqlProfileProvider的 ASP.NET 应用程序的Web.config文件。

<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 配置文件用于在数据源(如数据库)中存储和检索用户设置。 使用当前HttpContext属性访问Profile用户配置文件。 配置文件信息和属性值是使用配置文件提供程序管理的。

SqlProfileProvider类由 ASP.NET 用来存储和检索使用SQL Server数据库的 ASP.NET 应用程序的配置文件设置。 To use a SqlProfileProvider, you must first create the SQL Server database used by the SqlProfileProvider. 若要创建数据库 SqlProfileProvider,请运行在 [drive:]\WINDOWS\Microsoft.NET\Framework\2.0versionNumber 文件夹中找到的 aspnet_regsql.exe 工具,并指定 -A p 选项。 以下命令演示如何使用aspnet_regsql.exe可执行文件:

aspnet_regsql.exe -A p  

上面的示例未为创建的数据库指定名称,因此将使用默认名称。 默认数据库名称为 Aspnetdb。

计算机配置包含一个名为 AspNetSqlProvider 的默认SqlProfileProvider实例,该实例连接到本地计算机上的SQL Server。 可以使用提供程序的此实例,或在 ASP.NET 应用程序的Web.config文件中指定自己的实例。

备注

如果配置文件提供程序配置了使用集成安全性的连接字符串,则 ASP.NET 应用程序的进程帐户必须有权连接到SQL Server数据库。

构造函数

SqlProfileProvider()

创建 SqlProfileProvider 类的实例。

属性

ApplicationName

获取或设置要存储和检索其配置文件信息的应用程序的名称。

Description

获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。

(继承自 ProviderBase)
Name

获得一个友好名称,用于在配置过程中引用提供程序。

(继承自 ProviderBase)

方法

DeleteInactiveProfiles(ProfileAuthenticationOption, DateTime)

删除上次活动日期出现在指定日期和时间之前的配置文件的用户配置文件数据。

DeleteProfiles(ProfileInfoCollection)

从数据源中删除提供的一系列配置文件的配置文件属性和信息。

DeleteProfiles(String[])

从数据源中删除提供的一系列用户名的配置文件属性和信息。

Equals(Object)

确定指定对象是否等于当前对象。

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

检索一些配置文件的配置文件信息,在这些配置文件中,上次活动日期与指定的日期和时间相同或在其之前,而且配置文件的用户名与指定的名称匹配。

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

检索用户名与指定名称匹配的配置文件的配置文件信息。

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

对于上次活动日期与指定的日期和时间相同或在其之前的配置文件,检索它们的用户配置文件数据。

GetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32)

在数据源中检索配置文件的用户配置文件数据。

GetHashCode()

作为默认哈希函数。

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

获取数据源中上次活动日期与指定的 userInactiveSinceDate 相同或在其之前的配置文件的数量。

GetPropertyValues(SettingsContext, SettingsPropertyCollection)

从 SQL Server 配置文件数据库检索配置文件属性信息和值。

GetType()

获取当前实例的 Type

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

利用在 ASP.NET 应用程序的配置文件中指定的属性值初始化 SQL Server 配置文件提供程序。 此方法不能直接在代码中使用。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

利用指定的属性值更新 SQL Server 配置文件数据库。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅