在 MVC 5 项目上使用 ASP.NET Identity 但 httpcontext User.ProviderName 是“AspNetSqlRoleProvider" [英] Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is "AspNetSqlRoleProvider"

查看:17
本文介绍了在 MVC 5 项目上使用 ASP.NET Identity 但 httpcontext User.ProviderName 是“AspNetSqlRoleProvider"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 ASP.NET Identity(个人用户帐户)的 MVC 5 项目.作为数据库 ORM,我使用的是实体框架 6,而 IoC 由 Ninject 负责.

解决方案结构如下

  • MVC 项目-- 有我的控制器、视图和 ninject 设置.对于 Ninject,我从 nuget 获得了 Ninject.MVC3.
  • 数据项目--- 有我的 DataContext (IdentityDbContext) 和我的 ApplicationUser (IdentityUser).我的数据服务和所有存储库
  • 核心项目-- 拥有我所有的实体和接口

[Authorize] 属性工作正常,我必须登录才能访问带注释的操作,但是当我设置 [Authorize(Roles = "Admin")] 我得到

<块引用>

找不到存储过程dbo.aspnet_CheckSchemaVersion".

我在 CustomAuthorize 上创建了属性,它基本上是 Authorize 的副本,并注意到protected virtual bool AuthorizeCore(HttpContextBase httpContext) User.ProviderName 中的 httpcontext 是AspNetSqlRoleProvider".

所以我将 Rolemanages 添加到我的 web.config 中.这导致

<块引用>

配置错误说明:配置过程中发生错误处理为该请求提供服务所需的配置文件.请查看下面的特定错误详细信息并修改您的适当的配置文件.

解析器错误消息:找不到默认角色提供程序.

源错误:

第 53 行:--> 第 54 行:第 55 行:行56:第 57 行:

源文件:...myprojectWebUIweb.config行:55

那么这里的交易是什么?如何设置默认角色提供程序以使用 ASP.NET 标识?

解决方案

所以在我发布问题后我就找到了答案.我不得不补充

<前><模块>...<remove name="RoleManager"/>

做到了.但还有一个问题是为什么?

I have a MVC 5 project using ASP.NET Identity (Invidual user account). As Database ORM I am using Entity framework 6 and IoC is taken care by Ninject.

Solution structure is following

  • MVC project -- has my controllers, views and ninject setup. For Ninject I got Ninject.MVC3 from nuget.
  • Data project --- has my DataContext (IdentityDbContext) and my ApplicationUser (IdentityUser). My Data services and all repositories
  • Core project -- has all my entities and interfaces

[Authorize] attribute works fine and I have to login to access tha annotated action, but when I set [Authorize(Roles = "Admin")] I get

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

I created my on CustomAuthorize attibute which was basically a copy of Authorize and noticed that the httpcontext in protected virtual bool AuthorizeCore(HttpContextBase httpContext) User.ProviderName is "AspNetSqlRoleProvider".

So I added Rolemanages clear to my web.config. This resulted in

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: ...myprojectWebUIweb.config Line: 55

So whats the deal here? How can I set the Default Role Provider to use ASP.NET Identity?

解决方案

So right after I posted the question I figured the answer. I had to add

 <system.webServer>
    <modules>
...
      <remove name="RoleManager" />
    </modules>
  </system.webServer>

That did it. But there still is a question of why?

这篇关于在 MVC 5 项目上使用 ASP.NET Identity 但 httpcontext User.ProviderName 是“AspNetSqlRoleProvider"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆