How can I retrieve all the roles (groups) a user is a member of?

前端 未结 4 2285
孤独总比滥情好
孤独总比滥情好 2021-01-01 10:42

Is there a way to get a list of roles a Windows authenticated user is in, without explicitly checking by WindowsPrincipal.IsInRole method?

4条回答
  •  情歌与酒
    2021-01-01 11:23

    In an ASP.NET MVC site, you can do it like this:

    Add this to your Web.config:

    
      ...
      
      ...
    
    

    Then you can use Roles.GetRolesForUser() to get all the Windows groups that the user is a member of. Make sure you're using System.Web.Security.

提交回复
热议问题