Retrieve the Active Directory groups of the current user
How can I get the Ac开发者_运维百科tive Directory groups the current user belongs to?
Is there a way to do this using the DirectoryServices.AccountManagement
library?
I found how. It turned out to be very simple with DirectoryServices.AccountManagement
:
using System.DirectoryServices.AccountManagement;
PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetGroups();
IEnumerable<string> groupNames = groups.Select(x => x.SamAccountName);
精彩评论