简体   繁体   English

检索当前用户的Active Directory组

[英]Retrieve the Active Directory groups of the current user

How can I get the Active Directory groups the current user belongs to? 如何获得当前用户所属的Active Directory组?

Is there a way to do this using the DirectoryServices.AccountManagement library? 是否可以使用DirectoryServices.AccountManagement库来执行此操作?

I found how. 我找到了。 It turned out to be very simple with DirectoryServices.AccountManagement : 事实证明,使用DirectoryServices.AccountManagement非常简单:

using System.DirectoryServices.AccountManagement;

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM