Mvc Runtime error - The Role Manager feature has not been enabled

孤街浪徒 提交于 2019-11-29 10:52:12

By default the role manger is disabled, so you have to enable it explicitly:

<roleManager enabled="true" defaultProvider="DefaultRoleProvider">

I tried this in MVC 5 and it worked:

  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <roleManager enabled="true" />
  </system.web>

After adding the "roleManager" line shown above to the web.config, I could add a new role and add a user to the role without any exception:

   if (!Roles.RoleExists(_role))
      Roles.CreateRole(_role);

   if (!Roles.IsUserInRole(_username, _role))
      Roles.AddUserToRole(_username, _role);

With your DefaultRoleProvider try this

   <roleManager defaultProvider="DefaultRoleProvider" enabled ="true">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!