0

我正在设置我的 MVC 4 网站以使用 SqlMembershipProvider 和数据存储作为 SQL Server Express 11.0.21xx

我已经通过 NuGet 安装了通用提供程序
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>

连接字符串
<add name="DefaultConnection" connectionString="server=servername\instance;Database=imdb;User Id=sa; Password=passbird;" providerName="System.Data.SqlClient" />

问题出在哪里?我应该使用通用提供商吗?我不相信我应该运行新帐户控制器的 aspnet_regsql cos。

4

1 回答 1

1

我所要做的就是在 web.config 中将 DefaultMembershipProvider 更改为 SimpleMembershipProvider。type属性对于正确处理很重要。

<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>
于 2013-04-18T23:41:48.487 回答