SQL ServerMembership机制自定义数据库

(machine.config在%systemroot%\Microsoft.NET\Framework\v2.x\CONFIG目录下)

PS:此文只针对SQL Server数据库

您能够一向在machine.config里改变,可是那里一改变,会潜移默化到事后全体ASP.NET程序的安装,所以大家依旧在大团结的web.config中改变比较好

SQL Server 1        <membership>            
SQL Server 2            <providers>
SQL Server 3            <clear/>
SQL Server 4            <add name=”AspNetSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”remoteSqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”false” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Hashed” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” />            
SQL Server 5            </providers>
SQL Server 6        </membership>
SQL Server 7

因为相似教程使用的演示都是SQL Server 二〇〇六 Express版本的本土 ASPNETDB.MDF文件,如若自个儿要选择远程的Sql Server 二〇〇六服务器来说,须求进行部分安装。

另一种选拔是,大家率先

%systemroot%\Microsoft.NET\Framework\v2.x\

接下来修改Membership的provider.,修改的时候要求留意1个难点,因为machine.config中一度存在三个provider了,所以您平素扩大一个provider的话

SQL Server 8  <connectionStrings>
SQL Server 9    <add name=”LocalSqlServer” connectionString=”data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true” providerName=”System.Data.SqlClient” />
SQL Server 10  </connectionStrings>
SQL Server 11
SQL Server 12    <membership>
SQL Server 13      <providers>
SQL Server 14        <add name=”AspNetSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”LocalSqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”true” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Hashed” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” />
SQL Server 15      </providers>
SQL Server 16    </membership>
SQL Server 17

SQL Server 18        <membership defaultProvider=”RemoteSqlMembershipProvider”>
SQL Server 19            
SQL Server 20            <providers>
SQL Server 21            
SQL Server 22            <add name=”RemoteSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”remoteSqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”false” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Hashed” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” />
SQL Server 23            
SQL Server 24            </providers>

笔者们能够参考machine.config文件中的内容:

听大人说它的引路,能够很方便地钦赐你的服务器和数据库。完结今后,大家得以窥见,大家的长途服务器上制定数据库上曾经创办好了我们须要的表,视图,存款和储蓄进度等。

那边需求专注的另贰个题材尽管,provider的名字自然需若是AspNetSqlMembershipProvider,其余名字就会并发这么些颠倒是非:
Default Membership Provider could not be found.
因为原本早就钦点了AspNetSqlMembershipProvider为Default Provider.

Step2:那时候大家要求在web.config更改Membership的Provider

目录下的aspnet_regsql工具

 

Setp1:当你使用Membership, 大家得以窥见ASP.NET 2.0 已经在 SQL Server
二〇〇六 Express建立了无数表(aspnet_Membership等),视图,存款和储蓄进程等。当时大家协调的长距离服务器上并从未这个表。难道我们需求协调建?当然绝不,微软给大家准备了一个工具:

SQL Server 25    <connectionStrings>
SQL Server 26        <add name=”remoteSqlServer” connectionString=”server=..;uid=..;pwd=..;initial catalog=..” providerName=”System.Data.SqlClient” />
SQL Server 27    </connectionStrings>

在web.config中,首先创设大家协调的接连字符串:

SQL Server 28        <membership>            
SQL Server 29            <providers>
SQL Server 30            
SQL Server 31            <add name=”RemoteSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” connectionStringName=”remoteSqlServer” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”false” applicationName=”/” requiresUniqueEmail=”false” passwordFormat=”Hashed” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”7″ minRequiredNonalphanumericCharacters=”1″ passwordAttemptWindow=”10″ passwordStrengthRegularExpression=”” />            
SQL Server 32            </providers>
SQL Server 33        </membership>
SQL Server 34

在程序运转中仍然会去搜寻在machineconfig中定义的AspNetSqlMembershipProvider,因为十二分是default的。所以一种选取是,大家把这几个新的Provider设置为Default的。
clear原来的provider,然后再充实自身的provider(connectiongStringName设置为大家温馨的ConnectionString):

相关文章