2009-10-29 137 views
4

我想在iPlanet LDAP上进行分页搜索。这里是我的代码:“服务器不支持该控制的控制是关键”iPlanet LDAP和C#PageResultRequestControl

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 ... 
} 

当我运行它,我得到的是美国例外的剪断前行。快速谷歌搜索什么都没有。 iPlanet是否支持分页?如果是这样,我做错了什么?谢谢。

回答

10

所有符合LDAP v3标准的目录都必须包含服务器支持的控件的OID列表。可以通过发出带有空/空搜索根DN的基本级别搜索来获取列表,以获取目录服务器根DSE并读取多值supportedControl-attribute。

分页搜索支持的OID是1.2.840.113556.1.4.319

这里的代码片段,让你开始:

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制作的目录似乎支持分页。您可能最好使用我描述的方法检查服务器。

+0

你说得对,这台服务器不支持分页。我会找出我们正在运行的版本以及是否有升级计划。谢谢! – ristonj 2009-11-06 20:18:19

+1

+1:好的,很好的答案。 – Doug 2010-08-24 17:21:37