asp.net identity get all roles of logged in user

前端 未结 5 2181
遇见更好的自我
遇见更好的自我 2020-11-28 04:49

I created a role based menu for which I followed this tutorial. Some where down that page you\'ll see this line of code:

String[] roles = Roles.GetRolesForU         


        
5条回答
  •  死守一世寂寞
    2020-11-28 05:16

    Here's an extension method of the above solution.

        public static List Roles(this ClaimsIdentity identity)
        {
            return identity.Claims
                           .Where(c => c.Type == ClaimTypes.Role)
                           .Select(c => c.Value)
                           .ToList();
        }
    

提交回复
热议问题