get current user's role

前端 未结 7 1906
逝去的感伤
逝去的感伤 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:42

    Simplemembership in MVC4:

    Getting the User's role-

    var role = System.Web.Security.Roles.GetRolesForUser().Single();
    

    To check if the user belongs to a certain role-

    if (User.IsInRole("External"))
    

提交回复
热议问题