C# LDAP 搜索期间超出管理限制
我正在尝试进行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
许多 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.
删除了这一行,它起作用了:
必须从每个结果中获取 UID,而不仅仅是匹配结果,因此超出了管理限制。
Removed this line and it works:
Must have been grabbing the UID from every result instead of just a matching result and therefore was going over the Admin limit.