DirectorySearch.PageSize = 2不工作 [英] DirectorySearch.PageSize = 2 doesn't work

查看:175
本文介绍了DirectorySearch.PageSize = 2不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

     using (DirectorySearcher srch = new DirectorySearcher(String.Format("(memberOf=  {0})",p_Target.DistinguishedName)))
     {
            srch.PageSize = 2;
            SearchResultCollection results = results = srch.FindAll();
            int count = results.Count;
     }

计数= 3(三),而不是2。这是为什么?我不想把所有的结果只有一个页面。我知道,每页= 2是愚蠢的小,但我将在这种情况下,该值只是用于测试的目的(在现实中,它会更多)。

count = 3 (THREE) and not 2. Why is that? I don't want to have all results in just one page. I know that PageSize = 2 is silly small but I set that value in this case just for testing purpose (in reality it will be more).

推荐答案

的pageSize的是设置在一个分页搜索返回的记录数。分页的搜索是在LDAP协议层底层的东西。它是透明的给你。虽然你设置每页为2,DirectorySearcher从将返回所有的结果你,但你的情况有两种分页的搜索返回的数据包。

The pageSize is to set the number of records returned in one paged search. Paged search is an underlying thing at LDAP protocol level. It's transparent to you. Although you set the PageSize to 2, DirectorySearcher will return all the results for you but in your case in two paged search reply packets.

要做到你想要什么,你应该使用替代的sizeLimit。它将如何控制总量返回多条记录。

To do what you want, you should use SizeLimit instead. It will control how many records returned in total.

下面是更棘手的事情。在Windows Server有一个限制在服务器端设置。在每个分页搜索结果,只能返回至多1000个条目。所以,你需要的,如果你有结果超过1000项要小心设置每页和的sizeLimit。如果设置每页= 0(意味着无限制)和=的sizeLimit 0(意味着无限制),你会得到一个错误,因为Windows服务器无法回报你超过1000个条目的一个页面。如果设置每页= 800 =的sizeLimit 0(意味着无限制),你会得到所有你的结果,如果你看一下网络嗅探器,你会看到有一堆的LDAP分页的搜索结果。在每个分页的搜索结果,你看800项。

Here is one more tricky thing. Windows Server has a limit set on the server side. In each of the paged search result, it can only return at most 1000 entries. So, you need to be careful setting the PageSize and SizeLimit if you have the results more than 1000 entries. If you set PageSize=0 (meaning unlimited) and SizeLimit=0 (meaning unlimited), you will get an error because Windows server cannot return you more than 1000 entries in one single page. If you set Pagesize = 800 and SizeLimit=0 (meaning unlimited), you will get all your result and if you look at the network sniffer, you will see there are a bunch of LDAP paged search result. In each of the paged search result, you see 800 entries.

修改

EDIT

下面是一个更elabrated回答这个问题在您的评论。

Here is a more elabrated reply to the question in your comment.

嗯,有意思。请帮我   更好地了解这种机制:如果   在公元我有5000行中,每页   DirectorySearcher从被设定在1000,   的sizeLimit被设置为0和最大服务器   限制为1000多少呼叫   directorySearcher.FindAll()我需要   在我的code,以获得所有5000   结果如何? 5或1

Hm, interesting. Please help me understand better this mechanism: if in AD I have 5000 rows, PageSize of DirectorySearcher is set at 1000, SizeLimit is set to 0 and max server limit is 1000. How many call of directorySearcher.FindAll() I need to have in my code to get all 5000 results? 5 or 1

不管如何记录将许多数字要返回,你总是只需要1 DirectorySearcher从通话。 DirectorySearcher从将处理剩下的给你。它将聚集分页的搜索结果和present你在一个单一的IEnumerable,即使数据可能是从不同的应答报文。我猜你想设置PageLimit,因为你不希望所有5000结果返回一次全部和占据你的记忆。不要担心这一点。 DirectorySearcher从不会存储所有5000结果在你的记忆,只要你不抱每个返回的信息搜索结果的参考。它不会等到所有的应答报文回来无论是。当第一个应答包回来,将的FindAll()返回结果给你。如果你的程序是如此之快,你处理1000个结果之后,第二个分页搜索结果的数据包仍然没有到达。上的MoveNext()的调用将被阻塞,等到第二个分页搜索结果包recevied。

Regardless of how many number of records going to be returned, you always need only 1 call on DirectorySearcher. DirectorySearcher will handle the rest for you. It will aggregate the paged search result and present to you in one single IEnumerable even though the data might be from different reply packets. I guess you want to set PageLimit because you don't want all 5000 results returned all at once and occupy your memory. Don't worry on that. DirectorySearcher won't store all 5000 results in your memory as long as you don't hold reference on each of the returned SearchResult. It won't wait till all reply packets coming back either. As soon as the first reply packet coming back, the FindAll() returns the result to you. If your program is so fast that after you process the 1000 results, the second paged search result packet has still not yet arrived. The call on the MoveNext() will be blocked and wait till the second paged search result packet recevied.

这篇关于DirectorySearch.PageSize = 2不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆