0

我正在学习 MVC4 和实体框架的复数视觉教程。当我点击登录时我遇到了麻烦,用户和密码被正确保存在数据库中但是我得到了一个

Exception Details: System.InvalidOperationException: To call this method, the "Membership.Provider" property must be an instance of "ExtendedMembershipProvider".

当我尝试运行更新数据库时出错

这是我为数据库播种的方法

  protected override void Seed(eManager.Web.Infrastructure.DepartmentDb context)
    {

        context.Departments.AddOrUpdate(d => d.Name,
            new Department() { Name = "Engineering" },
            new Department() { Name = "Sales" },
            new Department() { Name = "Shipping" },
            new Department() { Name = "Human Resources" });

        if (Roles.RoleExists("Admin"))
        {
            Roles.CreateRole("Admin");
        }

        if (Membership.GetUser("rlemie") == null)
        {
            Membership.CreateUser("rlemie", "jumanji");
            Roles.AddUserToRole("rlemie", "Admin");
        }
    }
}

这是我的网络配置

    <?xml version="1.0" encoding="utf-8"?>
  <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    -->
  <configuration>
    <configSections>
      <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <connectionStrings>
      <add name="eManager.Web.Infrastructure.DepartmentDb" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=eManager.Web.Infrastructure.mdf;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\eManager.Web.Infrastructure.mdf" />
    </connectionStrings>
    <appSettings>
      <add key="webpages:Version" value="2.0.0.0" />
      <add key="webpages:Enabled" value="false" />
      <add key="PreserveLoginUrl" value="true" />
      <add key="ClientValidationEnabled" value="true" />
      <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
      <httpRuntime />
      <machineKey />
      <authentication mode="Forms">
        <forms loginUrl="~/Account/Login" timeout="2880" />
      </authentication>
      <pages controlRenderingCompatibilityVersion="4.0">
        <namespaces>
          <add namespace="System.Web.Helpers" />
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Optimization" />
          <add namespace="System.Web.Routing" />
          <add namespace="System.Web.WebPages" />
        </namespaces>
      </pages>
      <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="eManager.Web.Infrastructure.DepartmentDb" 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="eManager.Web.Infrastructure.DepartmentDb" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
        </providers>
      </membership>
      <roleManager defaultProvider="DefaultRoleProvider" enabled="true">
        <providers>
          <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="eManager.Web.Infrastructure.DepartmentDb" 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="eManager.Web.Infrastructure.DepartmentDb" />
        </providers>
      </sessionState>
    </system.web>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
          <parameter value="v11.0" />
        </parameters>
      </defaultConnectionFactory>
    </entityFramework>
  </configuration>

我的 Accountcontroller.cs 与复数教程中的不同,因为它使用 [InitializeSimpleMembership] 并且路由结构略有不同。

我更喜欢一个能解释我到底做错了什么的答案,因为我有一个解决方法可以解决它,但我不确定为什么,它会导致更多问题

4

0 回答 0