C# 如何使用>;在Ldap服务器上进行分页搜索;使用Novell.Directory.Ldap.NETStandard的10000个条目?

C# 如何使用>;在Ldap服务器上进行分页搜索;使用Novell.Directory.Ldap.NETStandard的10000个条目?,c#,.net-core,active-directory,ldap,C#,.net Core,Active Directory,Ldap,这与类似,但建议的解决方案不适用于我们 我们使用Novell.Directory.Ldap.NETStandard库,需要从Active Directory中获取10000多个条目。我们使用LdapVirtualListControl来处理分页,但该控件需要另一个控件:LdapSortControl。Active Directory有一个默认排序限制(10000),如果结果超过该限制,将发送错误53(不愿意执行)。如果省略了“Detect max result error”,我们将得到一个Lda

这与类似,但建议的解决方案不适用于我们

我们使用Novell.Directory.Ldap.NETStandard库,需要从Active Directory中获取10000多个条目。我们使用LdapVirtualListControl来处理分页,但该控件需要另一个控件:LdapSortControl。Active Directory有一个默认排序限制(10000),如果结果超过该限制,将发送错误53(不愿意执行)。如果省略了“Detect max result error”,我们将得到一个LdapException:“Unavailable Critical Extension”

        // Connection
        var ldapConn = new LdapConnection()
        {
            SecureSocketLayer = true,
        };
        ldapConn.UserDefinedServerCertValidationDelegate += (sender, certificate, chain, sslPolicyErrors) => true;
        ldapConn.Connect(host, 636);            
        ldapConn.Bind(username, password);


        var searchConstraints = (LdapSearchConstraints)ldapConn.SearchConstraints.Clone();
        int contentCount = 0, count = 0, startIndex = 1, pageSize = 1000;
        bool exit;

        do
        {
            // Add Virtual List Control
            searchConstraints.setControls(new List<LdapControl>
            {
                { new LdapVirtualListControl(startIndex, 0, pageSize - 1, contentCount) },
                { new LdapSortControl(new LdapSortKey[1] { new LdapSortKey("name") },true) }
            }.ToArray());

            // Perform search
            var searchResult = ldapConn.Search(container, scope, query, null, false, searchConstraints);

            // Get entries in page
            var inPageCount = 0;
            while (searchResult.hasMore())
            {

                // Detect max result error
                LdapSortResponse ldapControl = searchResult.ResponseControls?.OfType<LdapSortResponse>().FirstOrDefault();
                if (ldapControl != null && ldapControl.ResultCode == 53) throw new LdapResultLimitExceeded(string.Format("ActiveDirectory: Ldap result limit exceeded in {0}.", container));

                searchResult.next();
                inPageCount++;
            }

            // Check for more pages 
            var control = FindResponseControl(searchResult, ActiveDirectoryService.LDAP_SERVER_VIRTUAL_LIST_VIEW_OID);
            if (control != null)
            {
                var response = new LdapVirtualListResponse(control.ID, control.Critical, control.getValue());
                startIndex += pageSize;
                contentCount = response.ContentCount;
                if (count + pageSize > contentCount) count = contentCount; else count += inPageCount;
            }
            exit = control == null;
        } while (count < contentCount && contentCount > 0 && !exit);
//连接
var ldapConn=新的LdapConnection()
{
SecureSocketLayer=true,
};
ldapConn.UserDefinedServerCertValidationDelegate+=(发送方、证书、链、sslPolicyErrors)=>true;
ldapConn.Connect(主机,636);
ldapConn.Bind(用户名、密码);
var searchConstraints=(LdapSearchConstraints)ldapConn.searchConstraints.Clone();
int contentCount=0,count=0,startIndex=1,pageSize=1000;
布尔出口;
做
{
//添加虚拟列表控件
searchConstraints.setControls(新列表
{
{新的LdapVirtualListControl(startIndex,0,pageSize-1,contentCount)},
{new LdapSortControl(new LdapSortKey[1]{new LdapSortKey(“name”)},true)}
}.ToArray());
//执行搜索
var searchResult=ldapConn.Search(容器、范围、查询、null、false、searchConstraints);
//获取页面中的条目
var-inPageCount=0;
while(searchResult.hasMore())
{
//检测最大结果错误
LdapSortResponse ldapControl=searchResult.responseControl?.OfType().FirstOrDefault();
如果(ldapControl!=null&&ldapControl.ResultCode==53)抛出新的ldapresultlimitextended(string.Format(“ActiveDirectory:Ldap结果限制超出{0}.”,容器));
searchResult.next();
inPageCount++;
}
//查看更多页面
var control=FindResponseControl(搜索结果,ActiveDirectoryService.LDAP\u服务器\u虚拟\u列表\u视图\u OID);
if(控件!=null)
{
var response=new ldapvirtualistresponse(control.ID,control.Critical,control.getValue());
startIndex+=页面大小;
contentCount=response.contentCount;
如果(计数+页面大小>内容计数)计数=内容计数;否则计数+=inPageCount;
}
退出=控制==null;
}而(count0&&!退出);

我们应该如何处理超过10000个条目的搜索

如果只需要按顺序遍历结果集,则不需要使用LVL。我建议使用简单的分页结果控件()

如果只需要按顺序遍历结果集,则不需要使用LVL。我建议使用简单的分页结果控件()

如果您能分享到目前为止的进展,那将是非常棒的。添加了一个可复制的示例和一些更多信息。此示例适用于10000个条目,但不适用于10001个条目。如果您能分享您迄今为止的进展,那将是非常棒的。添加了一个可复制的示例和一些更多信息。此示例可用于10000个条目,但无法用于10001个条目