首先你要知道自己用户的AD Path,例如LDAP://Domain.com/CN=user1,CN=Users,DC=domain,DC=com
然后使用System.DirectoryServices.DirectoryEntry就可以取得对应的AD对象了,其中的"memberof"属性就是用户所在的group的列表。
You can have a look with the sample in MSDN with following URL too:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemdirectoryservicessearchresultclasstopic.htm
Something like this:
using System.DirectoryServices;
...
string adPath = @"LDAP://Domain.com/CN=user1,CN=Users,DC=domain,DC=com";
DirectoryEntry user = new DirectoryEntry (adPath);
foreach(object group in user.Properties["memberof"])
{
Console.WriteLine(group.ToString());
}
文章来源:http://computer.mblogger.cn/wucountry/posts/22924.aspx