asp.net - SimpleMembershipProvider无法正常工作

标签 asp.net asp.net-mvc entity-framework asp.net-mvc-4 simplemembership

我从VS2012开始了一个新的Internet项目,并试图对我的项目进行一些重组,但是我似乎无法保持SimpleMemberhsipProvider的正常运行。基本上,我要做的就是将模型对象与其他几个项目一起移动到一个核心项目中。我已经实现了Ninject,并试图通过使用存储库模式来获取我的数据来抽象一些实体。我真的不觉得我对当前项目进行了很大的更改,但是由于某种原因,现在启动应用程序时,我得到了:

{"The Role Manager feature has not been enabled."}



框架提供的ActionFilter是在以下情况下引发错误的位置:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "Id", "UserName", autoCreateTables: true);



叫做。

这是一些堆栈跟踪:

[ProviderException: The Role Manager feature has not been enabled.]
System.Web.Security.Roles.EnsureEnabled() +9561885
System.Web.Security.Roles.get_Provider() +8
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +104
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +100
InoutBoard.Core.Infrastructure.Filters.SimpleMembershipInitializer..ctor() in c:\Users\Kyle\Documents\Visual Studio 2012\Projects\InoutBoard\InoutBoard.Core\Infrastructure\Filters\InitializeSimpleMembershipAttribute.cs:42

[InvalidOperationException: The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588]
InoutBoard.Core.Infrastructure.Filters.SimpleMembershipInitializer..ctor() in c:\Users\Kyle\Documents\Visual Studio 2012\Projects\InoutBoard\InoutBoard.Core\Infrastructure\Filters\InitializeSimpleMembershipAttribute.cs:46



我将代码托管在github上的以下链接https://github.com/keroger2k/InoutBoard

最佳答案

第一种方式

检查sphair's answer out(在当前线程中)。

第二种方式

将以下程序集添加到web.config:

<system.web>
  <compilation debug="true" targetFramework="4.5">
    <assemblies>
      <add assembly="WebMatrix.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add assembly="WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </assemblies>
  </compilation>
</system.web>

更新
WebMatrix.WebData程序集包含一个启动方法,用于初始化成员资格/角色提供程序并启用RoleManager(PreApplicationStartCode.Start)。但是ASP.NET找不到适合您的情况的代码。通过添加这两行代码,我们强制ASP.NET在这些程序集中搜索PreApplicationStartMethodAttribute(s)

关于asp.net - SimpleMembershipProvider无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12254701/

相关文章:

asp.net - 刷新页面时如何禁止重新发布 - ASP.NET MVC

c# - mysql 函数的正确语法

asp.net - nHibernate 使用 Log4Net 进行日志记录,线程 session 问题

mysql - ASP.NET-Identity 限制 UserNameIndex 长度

asp.net - 使用 Razor Html.EditorFor 时限制文本框中字符的长度

c# - 客户端自定义不显眼的验证不起作用

asp.net-mvc - 使用 Javascript 访问 ASP.NET MVC 模型数据

asp.net-mvc - ASP.NET MVC运行IIS7部署问题

c# - Entity Framework Code First 隐含复合键上的可选一对多关系

c# - StoreGeneratedPattern 不适用于 DevArt Entity Framework ?