我在Visual Studio 2012中使用常见的登录、注册等页面启动了一个web应用程序。我有aspnet_xxx表的SQL数据库。所有成员资格、角色和配置文件都使用我到此数据库的连接字符串。然而,似乎应用程序使用的是来自machine.config的“会员”信息,而不是web.config。我在下面包括了两者的相关部分。在web.config的Membership部分,如果我离开defaultProvider="DefaultMembershipProvider",然后运行login.aspx并尝试登录,我得到一个错误消息"invalid object name: dbo.users",如果我将其从Membership部分删除,我不会得到这个错误,但是使用了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)的DB所有者身份登录。
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>发布于 2016-02-04 08:36:42
事实证明,我在我的web.config中是错误的system.wb版本。VS增加了4.0.0.0版本,我在GAC中有2.0.0.0版本。更改为2.0,这个问题就消失了。
https://stackoverflow.com/questions/35105973
复制相似问题