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

1

4

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?

Impetuosity answered 6/12, 2013 at 9:3 Comment(0)
I
18

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?

Impetuosity answered 6/12, 2013 at 9:25 Comment(1)
I came across this when upgrading a package via Nuget. The DLL that causes it (Microsoft.AspNet.WebPages.WebData) has changed in behaviour. An upgrade from 2.0.30506.0 to 3.2.3 meant that this config is treated differently with the result that my previously working app would now try to connect to a local SQL Server, which was not there.Flywheel

© 2022 - 2024 — McMap. All rights reserved.