How can I check if a user is in any one of a few different roles with MVC4 Simple membership?

后端 未结 8 857
日久生厌
日久生厌 2020-12-04 17:47

I understand that a good way to check if an user is in a role is:

if (User.IsInRole(\"Admin\"))
{

}

However How can I check if my user is

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 18:37

    What about this?

     if (User.Roles.Count() != 0)
         {
           //User is not in any role
         }else
         {
           //User is in at least one role
         }
    

提交回复
热议问题