最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to apply server side pagination for DirectorySearcher - Stack Overflow

programmeradmin5浏览0评论

What would be an effective way to do pagination with Active Directory searches in .NET? There are many ways to search in AD but so far I couldn't find how to do it effectively.

I have tried following one

using (var ctx = new PrincipalContext(ContextType.Domain, "SAMPLE","DC=sample,DC=com"))
using (var criteria = new UserPrincipal(ctx))
{
    criteria.SamAccountName = "*test*";
    using (var searcher = new PrincipalSearcher(criteria))
    {
        ((DirectorySearcher)searcher.GetUnderlyingSearcher()).SizeLimit = 10;
        var results = searcher.FindAll();
        foreach (var found in results)
        {
            
        }
    }
}

Here I was able to limit the search results to 10 but I wasn't able to get the total number of records corresponding to my search criteria.

I also tried using the System.DirectoryServices.DirectoryEntry and System.DirectoryServices.Protocols.SearchRequest but the only thing I can do is specify the page size.

So is the only way to fetch all the results on the client and do the Skip and Count there? I really hope that there are more effective ways to achieve this directly on the domain controller.

发布评论

评论列表(0)

  1. 暂无评论