我在Visual Studio 2012中启动了一个Web应用程序,使用通常的登录,注册等.pages。我有带有aspnet_xxx表的SQL数据库。所有成员身份、角色和配置文件都使用此数据库的连接字符串。但是,该应用程序似乎使用来自machine.config而不是web.config的"成员资格"信息。我将在下面包括两者的相关部分。在 web.config 的"成员资格"部分中,如果我离开 defaultProvider="DefaultMemberProvider",然后运行登录.aspx并尝试登录,我会收到一条错误消息,说"无效的对象名称:dbo.users",如果我将其从成员资格部分删除,我没有收到错误,但使用了 Machine.config 的成员资格部分。我知道这种情况发生的原因是我将web.config中的最小密码长度设置为6,而在machine.config中为7。在注册中.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( 身份登录没有问题。
机器配置:
<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-HPMSSQLSERVER2014;Initial Catalog=TT_V3;User ID=TT_User;password=abcdef" />
<add name="LocalSqlServer" providerName="System.Data.SqlClient"
connectionString="Data Source=M3-HPMSSQLSERVER2014;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>
事实证明,我的web.config中的system.wb版本是错误的。VS 添加了版本 4.0.0.0,我在 GAC 中有版本 2.0.0.0。更改为 2.0,问题消失了。