2011-10-19 64 views
1

沒有人知道在C#中構建LDAP查詢的任何強類型語言嗎?我想離開用於構建LDAP查詢的C#查詢語言

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

並且優選地具有用於構建邏輯查詢的流動api。

回答

3

那麼你可以嘗試LINQ到LDAP

在這裏你有一個tutorial

+0

這看起來很棒,爲什麼我沒有找到這個更早!? – hoetz

+0

@Malkier google我的朋友,他是我們的大朋友 – Frederiek

+0

經過快速瀏覽,它有一個限制,但是:您只能爲ONE對象類型(即用戶)構建查詢。在用戶或羣組或計算機上搜索似乎不可能,讓我們看看我們是否可以破解這個... – hoetz

0

http://linqtoad.codeplex.com/是一個很好的

+3

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Bucket

+0

@DesertIvy,通常我會同意你的看法,但這不是一些隨機鏈接到一些文章 - 它是codeplex項目的主頁。 – Matt

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使它很容易玩wi AD中的用戶和組!比早期的DirectoryEntry方法容易得多...