“asp.net会员提供商”是否可移植?我是否必须运行aspnet_regsql.exe为每台新机器设置它?
我将成员资格提供程序数据库导入Visual Studio Database Edition并检入我的源代码管理,并将其重新部署到另一台开发机器。从新机器,我得到以下错误。我该如何解决?谢谢!
在 'System.Web.Security.SqlMembershipProvider' 需要数据库模式兼容 使用架构版本'1'。然而 当前数据库架构不是 兼容此版本。你可以 需要安装兼容的 aspnet_regsql.exe的模式 (在框架中可用 安装目录),或升级 提供者到更新的版本。
答案 0 :(得分:3)
只要您在新的开发环境中拥有Framework 2.0或更高版本并访问包含架构的数据库,它就是“可移植的”。
aspnet_regsql.exe应用程序仅用于生成数据库模式。在指定您的提供者时,实际交易发生在web.config中。
只要您在连接字符串或包含成员资格提供程序架构的数据库中有.mdf文件引用,一切都应该正常工作。
连接字符串:
<connectionStrings>
<add name="LocalSQL" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=YourCatalog;Persist Security Info=True;User=sa;Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
会员提供者:
<membership defaultProvider="DefaultProvider" userIsOnlineTimeWindow="30">
<providers>
<clear/>
<add name="DefaultProvider" connectionStringName="LocalSQL" applicationName="DefaultApp" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Encrypted" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
答案 1 :(得分:0)
每个数据库都需要SQL成员资格提供程序。提供程序注册过程在数据库中创建某些表。如果那些表不存在,您将得到上述错误。
由于表是在数据库中创建的,因此您可以拥有任意数量的不同应用程序或开发计算机来共享单个SQL数据库。
但是如果你想要另一个提供者实例,因为你有一个不同的应用程序或需要与另一个SQL数据库交谈,那么你需要再次注册(创建表)。另一种可能性是使用SQL复制将表从一个数据库复制到另一个数据库。
您的应用程序可能需要修改web.config文件以确保它具有与现有SQL数据库的正确连接字符串。
答案 2 :(得分:0)
我也有这个问题。对我来说,我必须明确地给我的应用程序命名(在我的开发机器上它是“/”)。
的web.config:
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" applicationName="jobs"... />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" applicationName="jobs" ... />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="jobs" ... />
<add applicationName="jobs" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
然后在我的数据库中:
INSERT INTO [dbo].[aspnet_Applications]([ApplicationName], [LoweredApplicationName], [ApplicationId], [Description]) SELECT N'jobs', N'jobs', N'74b045ce-9c16-4e6a-b1ec-08504600a627', NULL