1

有人知道在 C# 中构建 LDAP 查询的任何强类型语言吗?我想离开

(&(|(objectClass=user)(objectClass=group)(objectClass=computer)(objectClass=contact))((objectGUID={0})))

并且最好有一个用于构建逻辑查询的流体 api。

4

3 回答 3

3

那么你可以试试 Linq to LDAP

在这里你有一个教程

于 2011-10-19T07:39:46.833 回答
0

http://linqtoad.codeplex.com/不错

于 2011-10-19T07:42:03.023 回答
0

如果您使用的是 .NET 3.5 及更高版本,您还可以查看System.DirectoryServices.AccountManagement(S.DS.AM) 命名空间。

在这里阅读所有相关信息:

基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // do something here....     
}

// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

// if found....
if (group != null)
{
   // iterate over members
   foreach (Principal p in group.GetMembers())
   {
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
      // do whatever you need to do to those members
   }
}

新的 S.DS.AM 使得在 AD 中与用户和组一起玩变得非常容易!比以前的DirectoryEntry方法容易得多...

于 2011-10-19T08:32:53.017 回答