我正在尝试使用System.DirectoryServices.Protocols.PageResultRequestControl
在Active Directory上执行分页搜索。
我确实在页面中获得了搜索结果,但是,我得到的searchResponse
对于总页数没有正确的TotalCount
。
不支持吗?或者我在这里遗漏了什么?
这是我为了实现上述而使用的示例代码。我正在使用System.DirectoryServices.Protocols
来查询Active Directory。
当PageResultRequestControl
添加页码时,除totalSize
外,一切都运行正常。
例如,在此代码中
LdapConnection connection = new LdapConnection(ldapDirectoryIdentifier, credential);
SearchRequest sr = new SearchRequest("", "(displayName=*)", System.DirectoryServices.Protocols.SearchScope.Subtree, new[] { "displayName"});
PageResultRequestControl pr = new PageResultRequestControl(50);
SearchOptionsControl so = new SearchOptionsControl(SearchOption.DomainScope);
sr.Controls.Add(pr);
sr.Controls.Add(so);
SearchResponse searchResponse;
while (true)
{
searchResponse = (SearchResponse)connection.SendRequest(sr);
if (searchResponse.Controls.Length != 1 || !(searchResponse.Controls[0] is PageResultResponseControl))
{
totalPageCount = 0;
return null;
}
PageResultResponseControl pageResponse = (PageResultResponseControl)searchResponse.Controls[0];
totalPageCount = pageResponse.TotalCount;
if (pageResponse.Cookie.Length == 0)
{
break;
}
else
{
pageRequest.Cookie = pageResponse.Cookie;
}
}
答案 0 :(得分:0)
正如文档所述,TotalCount属性包含估计结果集计数(https://technet.microsoft.com/en-us/library/system.directoryservices.protocols.pageresultresponsecontrol.totalcount)