注意:此类在 .NET Framework 2.0 版中是新增的。
对 ASP.NET 应用程序的配置文件信息在 SQL Server 数据库中的存储进行管理。
命名空间:System.Web.Profile
程序集:System.Web(在 system.web.dll 中)
Public Class SqlProfileProvider
Inherits ProfileProvider
Dim instance As SqlProfileProvider
public class SqlProfileProvider : ProfileProvider
public ref class SqlProfileProvider : public ProfileProvider
public class SqlProfileProvider extends ProfileProvider
public class SqlProfileProvider extends ProfileProvider
ASP.NET 配置文件用于在数据源(如数据库)中存储和检索用户设置。使用当前 HttpContext 的 Profile 属性可访问用户配置文件。使用配置文件提供程序来管理配置文件信息和属性值。
ASP.NET 使用 SqlProfileProvider 类来存储和检索使用了 SQL Server 数据库的 ASP.NET 应用程序的配置文件设置。要使用 SqlProfileProvider,您必须首先创建 SqlProfileProvider 使用的 SQL Server 数据库。要创建 SqlProfileProvider 使用的数据库,请运行 aspnet_regsql.exe 工具(可在 [drive:]\WINDOWS\Microsoft.NET\Framework\versionNumber 文件夹中找到),然后指定 -Ap 选项。下面的命令演示如何使用 aspnet_regsql.exe 可执行文件:
上面的示例未指定创建的数据库的名称,因此将使用默认名称。默认的数据库名称是 Aspnetdb。
计算机配置包含一个名为 AspNetSqlProvider 的默认 SqlProfileProvider 实例,该实例连接到本地计算机上的 SQL Server。您可以使用此提供程序实例,也可以在 ASP.NET 应用程序的 Web.config 文件中指定自己的实例。
注意 |
|---|
| 如果利用使用了集成安全性的连接字符串对配置文件提供程序进行配置,则 ASP.NET 应用程序的进程帐户必须具有连接到 SQL Server 数据库的权限。 |
下面的代码示例演示了配置为使用 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>
System.Object
System.Configuration.Provider.ProviderBase
System.Configuration.SettingsProvider
System.Web.Profile.ProfileProvider
System.Web.Profile.SqlProfileProvider
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
.NET Framework
受以下版本支持:2.0