C# LDAP 搜索期间超出管理限制

发布于 2024-09-08 20:13:36 字数 1369 浏览 2 评论 0原文

我正在尝试进行 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());

有什么想法可以解决此问题吗?

I am trying to do a LDAP Search however I keep getting the following error:

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

Here is the code: (The error is thrown at 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());

Any ideas how to get around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜访吸血鬼 2024-09-15 20:13:36

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

AD默认为1000或2000。我忘记了。 eDirectory 默认没有限制。其他则有所不同。

您可以要求管理员更改限制,或者对您的代码进行分页,以便一次仅获取一页(或有限数量的结果)。

Many LDAP server implementations have limits on how many results will be returned in a query.

AD defaults to 1000 or 2000. I forget offhand. eDirectory defaults to no limit. Others vary.

You can either ask the admins to change the limit, or else, page your code so it gets only a page (or limited number of results) at a time.

朦胧时间 2024-09-15 20:13:36

删除了这一行,它起作用了:

dirSearcher.PropertiesToLoad.Add("uid");

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

Removed this line and it works:

dirSearcher.PropertiesToLoad.Add("uid");

Must have been grabbing the UID from every result instead of just a matching result and therefore was going over the Admin limit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文