检索当前用户的Active Directory组

时间:2011-08-19 19:59:39

标签: c# .net security active-directory

如何获取当前用户所属的Active Directory组?

有没有办法使用DirectoryServices.AccountManagement库?

1 个答案:

答案 0 :(得分:18)

我找到了。事实证明DirectoryServices.AccountManagement

非常简单
using System.DirectoryServices.AccountManagement;

PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetGroups();

IEnumerable<string> groupNames = groups.Select(x => x.SamAccountName);