vider必须ExtendedMembershipProvide

vider必须ExtendedMembershipProvide

本文介绍了" Membership.Provider必须ExtendedMembershipProvider&QUOT的一个实例;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写使用Microsoft Visual Studio EX preSS 2012年网的MVC4网站。每当我在运行程序包管理器控制台更新-数据库,以下异常情况:

调用此方法时,Membership.Provider属性必须是实例
的ExtendedMembershipProvider。

这是我种方式:

 保护覆盖无效种子(GNSystem.Models.DataContext上下文)
    {
        context.Forums.AddOrUpdate(
                        新论坛{ForumName =你好},
                        新论坛{ForumName =世界},
                        新论坛{ForumName =! }
                        );
        context.UserProfiles.Add(新UserAccount {用户名=吉拉德,电子邮件[email protected]});
        WebSecurity.CreateUserAndAccount(吉拉德,123456);
        WebSecurity.Login(吉拉德,123456);
        context.Threads.AddOrUpdate(
            新的主题{主题=FirstThread,内容=真棒内容,ForumID = 1,用户名= 1},
            新的主题{主题=SecondThread,内容=真棒内容,ForumID = 1,用户名= 1}
            );
    }
 

我搜索solutions并增加在Web.config文件中的以下指令:

 <添加键=enableSimpleMembership值=真/>
 

但异常仍然抛出。

什么是这个原因?修改1:

 < XML版本=1.0编码=UTF-8&GT?;
<! -
  有关如何配置ASP.NET应用程序的更多信息,请访问:
  http://go.microsoft.com/fwlink/?LinkId=169433
   - >
<结构>
  < configSections>
    <! - 有关实​​体框架配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468  - >
    <节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本= 5.0.0.0,文化=中性公钥= b77a5c561934e089requirePermission =FALSE/>
  < / configSections>
  <的ConnectionStrings>
    <添加名称=DefaultConnection的connectionString =数据源=(的LocalDB)\ 11.0;初始目录= ASPNET-GNSystem-20120913165926;集成安全性= SSPI; AttachDBFilename = | DataDirectory目录| \ ASPNET,GNSystem-20120913165926.mdf的providerName =System.Data.SqlClient的/>
  < /的ConnectionStrings>
  <的appSettings>
    <添加键=enableSimpleMembership值=真/>
    <添加键=网页:版本值=2.0.0.0/>
    <添加键=网页:启用值=FALSE/>
    <添加键=preserveLoginUrl值=真/>
    <添加键=ClientValidationEnabled值=真/>
    <添加键=UnobtrusiveJavaScriptEnabled值=真/>
  < /的appSettings>
  <的System.Web>
    <编译调试=真正的targetFramework =4.5/>
    <的httpRuntime targetFramework =4.5/>
    <身份验证模式=形式>
      <形式loginUrl =〜/帐号/登录超时=2880/>
    < /认证>
    <网页>
      <命名空间>
        <加上命名空间=System.Web.Helpers/>
        <加上命名空间=System.Web.Mvc/>
        <加上命名空间=System.Web.Mvc.Ajax/>
        <加上命名空间=System.Web.Mvc.Html/>
        <加上命名空间=System.Web.Optimization/>
        <加上命名空间=System.Web.Routing/>
        <加上命名空间=System.Web.WebPages/>
      < /命名空间>
    < /页>
  < /system.web>
  < system.webServer>
    <验证validateIntegratedModeConfiguration =FALSE/>
    <处理>
      <删除名称=ExtensionlessUrlHandler-ISAPI-4.0_32bit/>
      <删除名称=ExtensionlessUrlHandler-ISAPI-4.0_64bit/>
      <删除名称=ExtensionlessUrlHandler集成-4.0/>
      <添加名称=ExtensionlessUrlHandler-ISAPI-4.0_32bit路径=*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS模块=IsapiModulescriptProcessor ​​=%WINDIR%\ Microsoft.NET \框架\ v4.0.30319 \ aspnet_isapi.dll的preCondition = classicMode,runtimeVersionv4.0,bitness32responseBufferLimit =0/>
      <添加名称=ExtensionlessUrlHandler-ISAPI-4.0_64bit路径=*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS模块=IsapiModulescriptProcessor ​​=%WINDIR%\ Microsoft.NET \ Framework64 \ v4.0.30319 \ aspnet_isapi.dll的preCondition = classicMode,runtimeVersionv4.0,bitness64responseBufferLimit =0/>
      <添加名称=ExtensionlessUrlHandler集成-4.0路径=*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSTYPE =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
    < /处理器>
  < /system.webServer>
  <运行>
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Helpers公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-2.0.0.0NEWVERSION =2.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.Mvc公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-4.0.0.0NEWVERSION =4.0.0.0/>
      < / dependentAssembly>
      < dependentAssembly>
        < assemblyIdentity名=System.Web.WebPages公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0-2.0.0.0NEWVERSION =2.0.0.0/>
      < / dependentAssembly>
    < / assemblyBinding>
  < /运行>
  <的EntityFramework>
    < defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework/>
  < /的EntityFramework>
< /结构>
 

解决方案

在您可以使用 WebSecurity.CreateUserAndAccount(吉拉德,123456); SimpleMembership必须初始化。这通常是在的AccountController与 [InitializeSimpleMembership] 属性,但因为你想打电话给你的种子中的这些方法,你将需要初始化它的另一种方式。

I'm writing a MVC4 Website using Microsoft Visual Studio express 2012 for web.Whenever I run "Update-Database" in the Package Manager Console, the following Exception occurs:

To call this method, the "Membership.Provider" property must be an instance
of "ExtendedMembershipProvider".

This is my Seed method:

protected override void Seed(GNSystem.Models.DataContext context)
    {
        context.Forums.AddOrUpdate(
                        new Forum { ForumName = "Hello" },
                        new Forum { ForumName = "World" },
                        new Forum { ForumName = "!" }
                        );
        context.UserProfiles.Add(new UserAccount { UserName = "Gilad", EMail = "[email protected]" });
        WebSecurity.CreateUserAndAccount("Gilad", "123456");
        WebSecurity.Login("Gilad", "123456");
        context.Threads.AddOrUpdate(
            new Thread { Subject = "FirstThread", Content = "Awesome Content", ForumID = 1, UserID = 1 },
            new Thread { Subject = "SecondThread", Content = "Awesome Content", ForumID = 1, UserID = 1 }
            );
    }

I searched for solutions and added the following directive in the Web.config file:

<add key="enableSimpleMembership" value="true" />

but the exception is thrown nonetheless.

What is the cause of this?Edit 1:

    <?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="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-GNSystem-20120913165926;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-GNSystem-20120913165926.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="enableSimpleMembership" value="true" />
    <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.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <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>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </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="1.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>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>
解决方案

Before you can use WebSecurity.CreateUserAndAccount("Gilad", "123456"); SimpleMembership must be initialized. This is typically done on the AccountController with the [InitializeSimpleMembership] attribute, but since you're trying to call these methods within your Seed, you will need to initialize it another way.

这篇关于&QUOT; Membership.Provider必须ExtendedMembershipProvider&QUOT的一个实例;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:17