The Role Manager feature has not been enabled
Solution 1:
You can do this by reading from 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>
Update:
For more information, check out this MSDN sample: https://msdn.microsoft.com/en-us/library/aa354509(v=vs.110).aspx
Solution 2:
If you got here because you're using the new ASP.NET
Identity
UserManager
, what you're actually looking for is the RoleManager
:
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
roleManager
will give you access to see if the role exists, create, etc, plus it is created for the UserManager