简体   繁体   English

从Active Directory查询用户的组成员身份

[英]Querying a user's group membership from Active Directory

I wanted to know if there's a fast way to query information from Active Directory. 我想知道是否有一种快速查询Active Directory信息的方法。

Specifically, I'm trying to query the current user's "member of" groups which starts with a given string, say "abc-" for example. 具体来说,我正在尝试查询当前用户的“成员”组,这些组以给定的字符串开头,例如“abc-”。

If any one can help me I would really appreciate it. 如果有人可以帮助我,我会非常感激。

Linq to ActiveDirectory是您可以考虑的选项。

You can do it in different ways, Managing Directory Security Principals in the .NET Framework 3.5 helps you this way: 您可以通过不同的方式执行此操作,在.NET Framework 3.5中管理目录安全性主体可以这样帮助您:

static void Main(string[] args)
{
  /* Retreiving a principal context
   */
  PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "WM2008R2ENT", "dc=dom,dc=fr", "TheUser", "ThePassword");

  /* Discribe the group You are looking for as a principal
   */
  GroupPrincipal gpPrincipal = new GroupPrincipal(domainContext);
  gpPrincipal.Name = "abc-*";

  /* Bind a searcher
   */
  PrincipalSearcher searcher = new PrincipalSearcher();
  searcher.QueryFilter = gpPrincipal;

  PrincipalSearchResult<Principal> hRes = searcher.FindAll();

  /* Read The result
   */
  foreach (GroupPrincipal grp in hRes)
  {
    Console.WriteLine(grp.Name);
    // You are looking for "grp.Members"
  }

  Console.ReadLine();
}

I hope it helps. 我希望它有所帮助。

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

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