Asp.net MVC 5 can't get user roles

二次信任 提交于 2019-12-04 18:18:40

You can get them via claims:

var roles = ((ClaimsIdentity)User.Identity).Claims
            .Where(c => c.Type == ClaimTypes.Role)
            .Select(c => c.Value);

To add a user to a role, you can do (Make sure the role exists in the database though):

var roleresult = UserManager.AddToRole(currentUser.Id, "RoleName");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!