我正在设置我的MVC 4网站,将SqlMembershipProvider与数据存储一起用作SQL Server Express 11.0.21xx
我已经通过NuGet安装了Universal Providers
PM > Install-Package Microsoft.AspNet.Providers
当我运行应用程序并转到localhost / Accounts / Register并提交表单时,我收到此错误
To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".
在这一行
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
帐户控制器已设置属性[InitializeSimpleMembership]
。但是由于上述错误,不会创建表。
由NuGet更新的web.config部分
<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="DefaultConnection"
applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<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>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider"
type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection"
applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection" />
</providers>
</sessionState>
的ConnectionString
<add name="DefaultConnection" connectionString="server=servername\instance;Database=imdb;User Id=sa; Password=passbird;" providerName="System.Data.SqlClient" />
问题出在哪里?我应该使用通用提供商吗?我不相信我应该运行新帐户控制器的aspnet_regsql cos。
答案 0 :(得分:1)
我所要做的就是在web.config中将DefaultMembershipProvider更改为SimpleMembershipProvider。 类型属性对于实现正确非常重要。
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"
connectionStringName="DefaultConnection"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider"
type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"
connectionStringName="DefaultConnection"
applicationName="/" />
</providers>
</roleManager>