Got the following ProviderException :
The Role Manager feature has not been enabled.
So far so good.
Is there somewhere a method that can be called to check if the Role Manager has been enabled or not?
Got the following ProviderException :
The Role Manager feature has not been enabled.
So far so good.
Is there somewhere a method that can be called to check if the Role Manager has been enabled or not?
I found this question due the exception mentioned in it. My Web.Config didn't have any
<roleManager>
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:
Check your Web.config and now you should have at least one
<providers>
tag inside Profile, Membership, SessionState tags and also inside the new RoleManager tag, like this:Add
enabled="true"
like so:Press F6 to Build and now it should be OK to proceed to a database update without having that exception:
update-database -verbose
and the Seed method will run just fine (if you haven't messed elsewhere) and create a few tables in your Database;Here is the code that you need to put in your Account Controller in MVC5 and later to get the list of roles of a user:
csharp public async Task<ActionResult> RoleAdd(string UserID) { return View(await UserManager.GetRolesAsync(UserID)).OrderBy(s => s).ToList()); }
There is no need to use
Roles.GetRolesForUser()
and enable the Role Manager Feature.I found 2 suggestions elsewhere via Google that suggested a) making sure your db connectionstring (the one that Roles is using) is correct and that the key to it is spelled correctly, and b) that the Enabled flag on RoleManager is set to true. Hope one of those helps. It did for me.
Did you try checking Roles.Enabled? Also, you can check Roles.Providers to see how many providers are available and you can check the Roles.Provider for the default provider. If it is null then there isn't one.
If you are using
ASP.NET Identity UserManager
you can get it like this as well:If you have changed key for user from Guid to Int for example use this code:
You can do this by reading from the boolean property at:
This is a direct read from the
enabled
attribute of theroleManager
element in theweb.config
:Update:
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx