没有人知道在C#中构建LDAP查询的任何强类型语言吗?我想离开用于构建LDAP查询的C#查询语言
(&(|(objectClass=user)(objectClass=group)(objectClass=computer)(objectClass=contact))((objectGUID={0})))
并且优选地具有用于构建逻辑查询的流动api。
没有人知道在C#中构建LDAP查询的任何强类型语言吗?我想离开用于构建LDAP查询的C#查询语言
(&(|(objectClass=user)(objectClass=group)(objectClass=computer)(objectClass=contact))((objectGUID={0})))
并且优选地具有用于构建逻辑查询的流动api。
那么你可以尝试LINQ到LDAP
在这里你有一个tutorial
如果你在.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使它很容易玩wi AD中的用户和组!比早期的DirectoryEntry
方法容易得多...
这看起来很棒,为什么我没有找到这个更早!? – hoetz
@Malkier google我的朋友,他是我们的大朋友 – Frederiek
经过快速浏览,它有一个限制,但是:您只能为ONE对象类型(即用户)构建查询。在用户或群组或计算机上搜索似乎不可能,让我们看看我们是否可以破解这个... – hoetz