Problem
The following ProviderException was thrown:
So far, everything has gone well.
Is there a mechanism that can be used to determine whether or not the Role Manager has been enabled?
Asked by gsharp
Solution #1
This can be accomplished by accessing the boolean property at:
System.Web.Security.Roles.Enabled
This is a direct read from the enabled attribute of the roleManager element in the web.config:
<configuration>
<system.web>
<roleManager enabled="true" />
</system.web>
</configuration>
Check out this MSDN example for additional information: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
Answered by Infotekka
Solution #2
If you came here because you’re seeking for the RoleManager: ASP.NET Identity UserManager, you’ve come to the wrong place.
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
roleManager gives you access to see if a role exists, create it, and so on, in addition to being created for the UserManager.
Answered by Serj Sagan
Solution #3
I discovered two tips on Google that suggested a) double-checking your db connectionstring (the one Roles is using) and making sure the key to it is typed correctly, and b) ensuring sure the Enabled option on RoleManager is set to true. I hope one of these suggestions becomes useful. That was the case for me.
Have you checked Roles.Enabled? You may also look at Roles.Providers to see how many providers are available, and Roles.Provider to find the default provider. If it’s null, it’s because there isn’t one.
Answered by Newclique
Solution #4
I found this question due the exception mentioned in it. My Web.Config didn’t have any tag. I realized that even if I added it (as Infotekka suggested), it ended up in a Database exception. After following the suggestions in the other answers in here, none fully solved the problem.
Since these Web.Config tags can be automatically generated, it felt wrong to solve it by manually adding them. If you are in a similar case, undo all the changes you made to Web.Config and in Visual Studio:
Answered by CPHPython
Solution #5
You can get it like this if you’re using ASP.NET Identity UserManager:
var userManager = Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
var roles = userManager.GetRoles(User.Identity.GetUserId());
Use this code if you’ve changed the user’s key from Guid to Int, for example:
var roles = userManager.GetRoles(User.Identity.GetUserId<int>());
Answered by Ogglas
Post is based on https://stackoverflow.com/questions/3874279/the-role-manager-feature-has-not-been-enabled