我有一个使用 ASP.NET 身份(个人用户帐户)的 MVC 5 项目。作为数据库 ORM,我使用的是 Entity Framework 6,而 IoC 由 Ninject 负责。
解决方案结构如下
-- 有我的 Controller 、 View 和 ninject 设置。对于 Ninject,我从 nuget 获得了 Ninject.MVC3。
--- 有我的 DataContext (IdentityDbContext) 和我的 ApplicationUser (IdentityUser)。我的
数据服务和所有存储库
-- 拥有我所有的实体和接口(interface)
[Authorize]
属性工作正常,我必须登录才能访问带注释的操作,但是当我设置 [Authorize(Roles = "Admin")]
我明白了Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
我创建了我的 CustomAuthorize 属性,它基本上是 Authorize 的副本,并注意到
protected virtual bool AuthorizeCore(HttpContextBase httpContext)
中的 httpcontext User.ProviderName 是“AspNetSqlRoleProvider”。所以我将 Rolemanages 添加到我的 web.config 中。这导致
Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Default Role Provider could not be found.
Source Error:
Line 53: --> Line 54: Line 55: Line 56: Line 57:
Source File: ...myproject\WebUI\web.config Line: 55
那么这里的交易是什么?如何设置默认角色提供程序以使用 ASP.NET 标识?
最佳答案
所以在我发布问题后,我想出了答案。我不得不添加
<模块>
...
模块>
做到了。但是还有一个问题,为什么?
关于entity-framework - 在 MVC 5 项目上使用 ASP.NET 标识,但 httpcontext User.ProviderName 为 "AspNetSqlRoleProvider",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20419899/