entity-framework - 在 MVC 5 项目上使用 ASP.NET 标识,但 httpcontext User.ProviderName 为 "AspNetSqlRoleProvider"

标签 entity-framework ninject asp.net-mvc-5 asp.net-identity

我有一个使用 ASP.NET 身份(个人用户帐户)的 MVC 5 项目。作为数据库 ORM,我使用的是 Entity Framework 6,而 IoC 由 Ninject 负责。

解决方案结构如下

  • MVC 项目
    -- 有我的 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/

    相关文章:

    entity-framework - 表 Controller : Flatten persistent data into DTO

    c# - Entity Framework 查询得到改进

    c# - 根据配置解析不同的实例

    c# - 如何使用 DisplayNameForModel?

    kendo-ui - 使用 Web API 2 Controller 的 Kendo Grid MVC 包装器示例

    javascript - 如何在不使用 html 包装器的情况下将 View 模型数据绑定(bind)到 Kendo DropDownlist

    entity-framework - 在实体( Entity Framework )中创建非映射属性

    .net - 如何使用流畅的 API 添加主键 - Entity Framework EF 4.x Code First

    c# - System.Web.Http 的 NuGet 更新后出现 FileLoadException

    dependency-injection - 如何设置 Ninject DI 以创建 Hyprlinkr RouteLinker 实例