问题描述
我正在尝试在 iPlanet LDAP 上进行分页搜索.这是我的代码:
I am trying to do a paged search on an iPlanet LDAP. Here's my code:
LdapConnection ldap = new LdapConnection("foo.bar.com:389");
ldap.AuthType = AuthType.Anonymous;
ldap.SessionOptions.ProtocolVersion = 3;
PageResultRequestControl prc = new PageResultRequestControl(1000);
string[] param = new string[] { "givenName" };
SearchRequest req = new SearchRequest("ou=people,dc=bar,dc=com", "(ou=MyDivision)", SearchScope.Subtree, param);
req.Controls.Add(prc);
while (true)
{
SearchResponse sr = (SearchResponse)ldap.SendRequest(req);
... snip ...
}
当我运行它时,我得到一个异常,指出服务器不支持该控件.该控件很关键"在剪辑之前的行上.快速的 Google 搜索一无所获.iPlanet 支持分页吗?如果是这样,我做错了什么?谢谢.
When I run this, I get an exception that states "The server does not support the control. The control is critical" on the line before the snip. Quick Google search turns up nothing. Does iPlanet support paging? If so, what am I doing wrong? Thanks.
推荐答案
所有符合 LDAP v3 的目录都必须包含服务器支持的控件的 OID 列表.可以通过发出具有空/空搜索根 DN 的基本级别搜索来访问该列表,以获取目录服务器根 DSE 并读取多值 supportedControl
-attribute.
All LDAP v3 compliant directories must contain a list of OIDs for the controls that the server supports. The list can be accessed by issuing a base-level search with a null/empty search root DN to get the directory server root DSE and reading the multi-value supportedControl
-attribute.
分页搜索支持的 OID 是 1.2.840.113556.1.4.319.
The OID for paged search support is 1.2.840.113556.1.4.319.
这里有一个代码片段可以帮助您入门:
Here's a code snippet to get you started:
LdapConnection lc = new LdapConnection("ldap.server.name");
// Reading the Root DSE can always be done anonymously, but the AuthType
// must be set to Anonymous when connecting to some directories:
lc.AuthType = AuthType.Anonymous;
using (lc)
{
// Issue a base level search request with a null search base:
SearchRequest sReq = new SearchRequest(
null,
"(objectClass=*)",
SearchScope.Base,
"supportedControl");
SearchResponse sRes = (SearchResponse)lc.SendRequest(sReq);
foreach (String supportedControlOID in
sRes.Entries[0].Attributes["supportedControl"].GetValues(typeof(String)))
{
Console.WriteLine(supportedControlOID);
if (supportedControlOID == "1.2.840.113556.1.4.319")
{
Console.WriteLine("PAGING SUPPORTED!");
}
}
}
我认为 iPlanet 不支持分页,但这可能取决于您使用的版本.较新版本的 Sun 制造的目录似乎支持分页.您最好使用我描述的方法检查您的服务器.
I don't think iPlanet supports paging but that might depend on the version you're using. Newer versions of Sun-made directories seem to support paging. You're probably best off checking your server using the method I've described.
这篇关于iPlanet LDAP 和 C# PageResultRequestControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!