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

后端 未结 3 1396
一整个雨季
一整个雨季 2020-12-19 11:34

I am trying to implement basic role management manually. When a user logs in if they are admin or not they are added to a role

I am getting this error:Except

相关标签:
3条回答
  • 2020-12-19 11:59

    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);
    
    0 讨论(0)
  • 2020-12-19 12:07

    With your DefaultRoleProvider try this

       <roleManager defaultProvider="DefaultRoleProvider" enabled ="true">
    
    0 讨论(0)
  • 2020-12-19 12:08

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

    <roleManager enabled="true" defaultProvider="DefaultRoleProvider">
    
    0 讨论(0)
提交回复
热议问题