Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is “AspNetSqlRoleProvider”

情到浓时终转凉″ 提交于 2020-01-11 05:45:08

问题


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: ...myproject\WebUI\web.config Line: 55

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


回答1:


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?



来源:https://stackoverflow.com/questions/20419899/using-asp-net-identity-on-mvc-5-project-but-httpcontext-user-providername-is-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!