1

我正在尝试进行 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 = "my.email@mycompany.com";

        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());

任何想法如何解决这个问题?

4

2 回答 2

1

删除了这一行,它的工作原理:

dirSearcher.PropertiesToLoad.Add("uid");

必须从每个结果中获取 UID,而不仅仅是匹配结果,因此超出了管理员限制。

于 2010-07-08T16:08:43.517 回答
1

许多 LDAP 服务器实现对查询中返回的结果数量有限制。

AD 默认为 1000 或 2000。我忘记了。eDirectory 默认为无限制。其他各不相同。

您可以要求管理员更改限制,或者对您的代码进行分页,使其一次只能获得一个页面(或有限数量的结果)。

于 2010-07-08T16:08:16.857 回答