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

后端 未结 3 1419
一整个雨季
一整个雨季 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条回答
  •  猫巷女王i
    2020-12-19 11:59

    I tried this in MVC 5 and it worked:

      
        
        
        
        
      
    

    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);
    

提交回复
热议问题