2009-10-29 149 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