2010-07-08 48 views
1

我試圖做一個LDAP搜索,但是我不斷收到以下錯誤:超出在C#LDAP搜索管理限制

Unhandled Exception: System.Runtime.InteropServices.COMException (0x80072024): T 
he administrative limit for this request was exceeded. 

    at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext 
() 
    at System.DirectoryServices.DirectorySearcher.FindOne() 

下面是代碼:

(誤差在FindOne()拋出)
 DirectoryEntry dirEntry = new DirectoryEntry("LDAP://myldap.com:1701/ou=People,o=My Company,c=CA", "", "", AuthenticationTypes.Anonymous); 
     DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry); 

     string filter = "mail"; 
     string filterValue = "[email protected]"; 

     dirSearcher.Filter = string.Format("({0}={1})", filter, filterValue); 

     SortOption sortOption = new SortOption(filter, SortDirection.Ascending); 

     dirSearcher.Sort = sortOption; 
     dirSearcher.PropertiesToLoad.Add("uid"); 
     dirSearcher.SearchScope = SearchScope.Subtree; 

     SearchResult result = dirSearcher.FindOne(); 

     DirectoryEntry directEntry = result.GetDirectoryEntry(); 
     Console.WriteLine("Result: {0}", directEntry.Properties["uid"].Value.ToString()); 

任何想法如何解決這個問題?

+0

此LDAP是否針對Active Directory或針對某個其他LDAP目錄?如果其他:哪一個? – 2010-07-08 16:02:31

+0

是活動目錄 – 2010-07-08 16:07:38

+0

LDAP路徑看起來有點奇怪 - 我不確定AD是否支持'o ='和'c ='這樣的東西 - 通常在OpenLDAP或Novell eDirectory中使用。 – 2010-07-08 16:15:32

回答

1

刪除這條線,它的工作原理:

dirSearcher.PropertiesToLoad.Add("uid"); 

一定是從每個結果抓住UID,而不是僅僅的匹配結果,因此打算在管理限制。

+0

根據理查德米勒的參考網站(http://www.rlmueller.net/UserAttributes.htm),活動目錄似乎不包含「uid」屬性 - 必須是你正在尋找的其他東西.... – 2010-07-08 16:16:58

+0

我在http://www.rlmueller.net/References/Schema.xls下看到「uid」 – 2010-07-08 16:32:09

1

許多LDAP服務器實現對查詢中返回多少結果有限制。

AD默認爲1000或2000.我忘記了手。 eDirectory默認沒有限制。其他不同。

您可以要求管理員更改限制,否則請分頁您的代碼,以便一次只獲得一個頁面(或有限數量的結果)。