DefaultConnection和membership - localsqlserver和defaultconnection之间的连接是什么

Lar*_*rsi 4 asp.net entity-framework connection-string asp.net-membership

嗯...我真的无法理解这一点.

在web.config我有:

<connectionStrings>
   <clear /> <!--- need this to prevent using LocalSqlServer from machine.config or somewhere becouse it is not present when when publish to hosting -->
   <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Goaly-20120615111028;Integrated Security=SSPI" />  
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <!-- I think this line is telling asp.net that I want the membership working agains defaultconnection, and not LocalSqlServer connection????? -->
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
Run Code Online (Sandbox Code Playgroud)

但后来它抱怨:

The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Run Code Online (Sandbox Code Playgroud)

当我在设置选项卡中使用VS2012 RC的发布时,我得到一个ModelContext和一个DefaultConnection,那么这应该如何工作呢?

我想要的只是在与modelcontext创建的表相同的数据库中获取成员资格表.

这应该是如此,但我必须过分复杂一些.

谢谢你的帮助.

问候

Larsi

Pau*_*ter 6

Windows机器上所有网站的默认设置都继承了2个配置文件的设置:machine.config和web.config,可以在Windows/Microsoft.NET/Framework目录(或64位Framework64)/版本中找到/配置.

以下是machine.config默认版本的片段:

<system.web>
    <processModel autoConfig="true"/>
    <httpHandlers/>
    <membership>
        <providers>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.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=""/>
        </providers>
    </membership>
    <profile>
        <providers>
            <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </profile>
    <roleManager>
        <providers>
            <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
            <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </roleManager>
</system.web>
Run Code Online (Sandbox Code Playgroud)

所以你的问题的答案是:machine.config建立了对LocalSqlServer连接的依赖.当您添加<clear/>标记作为此问题建议的其他答案时,您将删除对名为的成员资格提供程序AspNetSqlMembershipProvier的引用,并使用它引用LocalSqlServer.