get current user's role

前端 未结 7 1927
逝去的感伤
逝去的感伤 2020-12-29 20:11

Is there any way to get the explicit role that a user belongs to in my controller? This assumes using ASP.NET Membership and Role Providers. \"IsInRole\" doesn\'t work - I n

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 20:41

    You can get the current user's role with Roles.GetRolesForUser().

    To check if a user belongs to a role here is what I did:

    Roles.GetRolesForUser().Contains("Administrator")
    

提交回复
热议问题