Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 652
Vili Avatar asked Dec 01 '22 17:12

Vili


1 Answers

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?

like image 81
Vili Avatar answered Jan 03 '23 09:01

Vili