Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

asp.net - Setting up the default AspNetSqlProvider to point to remote database

When starting a new project that required the use of membership providers I found that I could not connect to a remote database that contained the membership database.

I ran aspnet_regsql and was able to create the membership database on the remote server but when I go to ASPNET Configuration (cassini development server) it will not connect to the remote server.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After much searching I found that the default Membership Provider specified in machine.config (c:windowsMicrosoft.NETFrameworkv2.0.50727CONFIG) was always pointing to a SQL Server running on the localhost.

Instead of modifying machine.config there is a way to set it up in the projects web.config:

1) Setup the connection string to the remote database

    <connectionStrings>
      <add name="aspnet_membership" connectionString="<your_connection_string>"/>
    </connectionStrings>

2) In <system.web> redefine the default provider:

  <membership>
    <providers>
        <remove name="AspNetSqlMembershipProvider"/>
        <add name="AspNetSqlMembershipProvider" 
            type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            connectionStringName="aspnet_membership"
            enablePasswordRetrieval="false" 
            enablePasswordReset="true" 
            requiresQuestionAndAnswer="true" 
            applicationName="/" 
            requiresUniqueEmail="false" 
            passwordFormat="Hashed" 
            maxInvalidPasswordAttempts="5" 
            minRequiredPasswordLength="7" 
            minRequiredNonalphanumericCharacters="1" 
            passwordAttemptWindow="10" 
            passwordStrengthRegularExpression=""/>
    </providers>
  </membership>

The <remove name="AspNetSqlMembershipProvider"/> is key! All the other key/values were taken directly from machine.config


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...