沒有人知道在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