如何使用Novell.Directory.Ldap.NETStandard和“简单分页结果"控件在Ldap服务器上进行分页搜索?

编程入门 行业动态 更新时间:2024-10-15 16:24:20
本文介绍了如何使用Novell.Directory.Ldap.NETStandard和“简单分页结果"控件在Ldap服务器上进行分页搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用Novell.Directory.Ldap.NETStandard在Active Directory中进行分页搜索( github/dsbenghe/Novell.Directory.Ldap.NETStandard )和简单分页结果"控件( ldapwiki/wiki/Simple%20Paged%20Results%20Control ).

I'm trying to do a paged search in an Active Directory using Novell.Directory.Ldap.NETStandard (github/dsbenghe/Novell.Directory.Ldap.NETStandard) and Simple Paged Results control (ldapwiki/wiki/Simple%20Paged%20Results%20Control).

第一页工作正常,但是第二页在searchResult.next()行上抛出"Unavailable Critical Extension".在事件日志中查找ActiveDirectory时,我发现:

First page works fine but the second one throws "Unavailable Critical Extension" on the searchResult.next() line. When looking in the event log for ActiveDirectory I found:

00000057:LdapErr:DSID-0C090809,注释:错误处理控件,数据0,v23f0 0000208D:NameErr:DSID-03100213,问题2001(NO_OBJECT),数据0,最佳匹配项:

00000057: LdapErr: DSID-0C090809, comment: Error processing control, data 0, v23f0 0000208D: NameErr: DSID-03100213, problem 2001 (NO_OBJECT), data 0, best match of:

我们还尝试了LdapVirtualListControl,但遇到了另一个问题,请参见如何使用>在Ldap服务器上进行分页搜索使用Novell.Directory.Ldap.NETStandard 10000个条目?

We have also tried the LdapVirtualListControl but run into a different problem, see How to do a paged search on an Ldap server with > 10000 entries using Novell.Directory.Ldap.NETStandard?

这是我们用来复制的简化代码:

Here are a simplified code we use to reproduce:

// Connection var ldapConn = new LdapConnection() { SecureSocketLayer = true, }; ldapConn.UserDefinedServerCertValidationDelegate += (sender, certificate, chain, sslPolicyErrors) => true; ldapConn.Connect(host, 636); ldapConn.Bind(username, password); // Constraints LdapSearchConstraints searchConstraints = (LdapSearchConstraints)_conn.SearchConstraints.Clone(); int pageSize = 100, count = 0; bool exit = false; const string LDAP_SERVER_SIMPLE_PAGED_RESULT_OID = "1.2.840.113556.1.4.319"; LdapControl pageControl = null; do { int inPageCount = 0; // Add Simple Paged Result control var request = new Asn1Sequence(2); request.add(new Asn1Integer(pageSize)); request.add(pageControl == null ? new Asn1OctetString("") : new Asn1OctetString(pageControl.getValue())); searchConstraints.setControls( new LdapControl(LDAP_SERVER_SIMPLE_PAGED_RESULT_OID, true, request.getEncoding(new LBEREncoder())) ); // Get search result var searchResult = (LdapSearchResults)ldapConn.Search(container, LdapConnection.SCOPE_SUB, query, null, false, searchConstraints); while (searchResult.hasMore()) { // Detect simple paged result control pageControl = searchResult.ResponseControls?.Where(rc => rc.ID == LDAP_SERVER_SIMPLE_PAGED_RESULT_OID).FirstOrDefault(); if (pageControl != null) break; var nextEntry = searchResult.next(); inPageCount++; } count += inPageCount; // Exit if no more pages exit = pageControl == null; } while (!exit);

推荐答案

为什么代码不起作用

根据 RFC 简单页面结果控件编码为

Why code does not work

According to RFC Simple Paged Results Control encoded as

realSearchControlValue ::= SEQUENCE { size INTEGER (0..maxInt), -- requested page size from client -- result set size estimate from server cookie OCTET STRING } 在下一个屏幕截图(来自Wireshark)中可能会清楚可见.

realSearchControlValue ::= SEQUENCE { size INTEGER (0..maxInt), -- requested page size from client -- result set size estimate from server cookie OCTET STRING } which may be clear seen on the next screenshot (taken from Wireshark).

:

当客户端将控制权添加到请求中时, size 会设置为页面中所需的元素数,而 cookie 是上次服务器响应中的不透明结构(对于第一个请求为空).

When the client adds control to the request, size is set to the desired number of elements in the page and cookie is the opaque structure from the previous server response (empty for the first request).

当您尝试在请求中构造控件时,您错误地添加了整个控件值而不是cookie(pageControl.getValue()):

When you try to construct control in your request, you mistakenly add the whole control value instead of cookie (pageControl.getValue()):

var request = new Asn1Sequence(2); request.add(new Asn1Integer(pageSize)); request.add(pageControl == null ? new Asn1OctetString("") : new Asn1OctetString(pageControl.getValue()));

它使第一个请求之后的所有请求都不正确.

It makes all requests after the first one incorrect.

看看 github/metacube/PagedResultsControl . 我创建了类型化的简单分页结果控件实现,该实现封装了解码/编码逻辑.对于来自Active Directory的100 000多个条目,对我来说效果很好.

Take a look at github/metacube/PagedResultsControl. I've created typed Simple Paged Results Control implementation which encapsulates decoding/ encoding logic. Works perfectly fine for me in the case of 100 000+ entries from Active Directory.

测试应用程序显示了基本用法.

The test application shows basic usage.

更多推荐

如何使用Novell.Directory.Ldap.NETStandard和“简单分页结果"控件在Ldap服务器上进行分页搜索?

本文发布于:2023-11-17 02:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   如何使用   控件   器上   简单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!