玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

Profile with sqlserver

Posted on 2008-06-29 11:47 玄铁剑 阅读(277) 评论(0)  编辑 收藏 引用 所属分类: asp.net

ASP.NET 配置文件用于在数据源(如数据库)中存储和检索用户设置。使用当前 HttpContextProfile 属性可访问用户配置文件。使用配置文件提供程序来管理配置文件信息和属性值。

ASP.NET 使用 SqlProfileProvider 类来存储和检索使用了 SQL Server 数据库的 ASP.NET 应用程序的配置文件设置。要使用 SqlProfileProvider,您必须首先创建 SqlProfileProvider 使用的 SQL Server 数据库。要创建 SqlProfileProvider 使用的数据库,请运行 aspnet_regsql.exe 工具(可在 [驱动器:]\WINDOWS\Microsoft.NET\Framework\versionNumber 文件夹中找到),然后指定 -Ap 选项。下面的命令演示如何使用 aspnet_regsql.exe 可执行文件:

aspnet_regsql.exe -Ap


上面的示例未指定创建的数据库的名称,因此将使用默认名称。默认的数据库名称是 Aspnetdb。
计算机配置包含一个名为 AspNetSqlProvider 的默认 SqlProfileProvider 实例,该实例连接到本地计算机上的
SQL Server。您可以使用此提供程序实例,也可以在 ASP.NET 应用程序的 Web.config 文件中指定自己的实例。
下面的代码示例演示了配置为使用 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>
只有注册用户登录后才能发表评论。