会员信息来自machine.config

时间:2016-01-30 19:17:36

标签: c# asp.net .net-4.5 membership-provider

我在Visual Studio 2012中使用常用的登录,注册等页面启动了一个Web应用程序。我有aspnet_xxx表的SQL数据库。所有成员,角色和配置文件都使用我的连接字符串到此数据库。但是,应用程序似乎使用" Membership"来自machine.config而不是web.config的信息。我包括以下两个部分的相关部分。在web.config的Membership部分,如果我离开defaultProvider =" DefaultMembershipProvider",然后运行login.aspx并尝试登录,我收到错误说"无效的对象名称:dbo。用户",如果我从会员部分删除它,我没有收到错误,但使用了Machine.config的Membership部分。我知道这种情况发生的原因是我将web.config中的最小密码长度设置为6,而在machine.config中它是7。在Register.aspx中,我有以下一行:

Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.

,显示为:

Passwords are required to be a minimum of 7 characters in length.

我猜在错误消息中显示的dbo.users表是数据库中machine.config连接字符串所指的内容。 我使用SSMS并没有问题,并以此数据库的数据库所有者(TTUser)身份登录。

Machine.config中:

<connectionStrings>
  <add name="LocalSqlServer" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>

<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="false" 
            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>

we.config:

<connectionStrings>
    <remove name="TTConnection"/>
    <remove name="LocalSqlServer"/>

    <add name="TTConnection" providerName="System.Data.SqlClient"
      connectionString="Data Source=M3-HP\MSSQLSERVER2014;Initial Catalog=TT_V3;User ID=TT_User;password=abcdef" />

    <add name="LocalSqlServer" providerName="System.Data.SqlClient"
      connectionString="Data Source=M3-HP\MSSQLSERVER2014;Initial Catalog=TT_V3;User ID=TT_User;password=abcdef" />
</connectionStrings>

<profile defaultProvider="DefaultProfileProvider">
    <providers>
       <add name="DefaultProfileProvider"
         type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         connectionStringName="TTConnection" applicationName="/" />
   </providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
   <providers>
       <add connectionStringName="TTConnection"
         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false" 
         maxInvalidPasswordAttempts="5" 
         minRequiredPasswordLength="6"
         minRequiredNonalphanumericCharacters="0" 
         passwordAttemptWindow="10"
         applicationName="/" 
         name="DefaultMembershipProvider" 
         type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </providers>
</membership>
<roleManager enabled="true">
    <providers>
        <add connectionStringName="TTConnection" applicationName="/"
          name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </providers>
</roleManager>

1 个答案:

答案 0 :(得分:0)

事实证明我的web.config中的system.wb版本是错误的。 VS添加了4.0.0.0版,我在GAC中使用了2.0.0.0版。改为2.0,问题就消失了。