Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Call to PageResultRequestControl fails

679 views
Skip to first unread message

Joe Kaplan

unread,
Apr 5, 2007, 11:09:26 AM4/5/07
to
Can you show a brief example of the code that isn't working? You shouldn't
have any trouble doing a paged search with either AD or ADAM, so something
must be a little off here.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Dattesh Lotlikar" <Dattesh...@discussions.microsoft.com> wrote in
message news:4993E9D8-BEF8-49CD...@microsoft.com...
> Hello All,
> I'm trying to run the Page Search Technology sample, as per
> (http://msdn2.microsoft.com/en-us/library/tehcbaa3.aspx), but it fails
> with
> "The server does not support the control. The control is critical." error.
> I verified the supportedControl property of Active Directory
> Server,
> it does have "1.2.840.113556.1.4.319" defined.
> Do I need to configure Active Directory Server before the paging
> control request can be passed?
>
> Thanks & Regards,
> Dattesh Lotlikar


Dattesh Lotlikar

unread,
Apr 6, 2007, 1:38:02 AM4/6/07
to
Hello Joe,
Following is the code that was tried:

***************
public static void Main(string[] args)
{
try
{

string ldapServer = "ps4027:389";
string targetOU = "OU=test2,DC=appliedidentity,DC=com";

int pageSize = 5;

LdapConnection ldapConnection = new LdapConnection(ldapServer);
ldapConnection.AutoBind = true;
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.SessionOptions.AutoReconnect = true;

NetworkCredential credential
= new
NetworkCredential("cn=administrator,cn=users,dc=appliedidentity,dc=com",
"password");

Console.WriteLine("\r\nBinding to server...");
ldapConnection.Bind(credential);
Console.WriteLine("Done...");

Console.WriteLine("\r\nPerforming Search....");

string ldapSearchFilter = "(objectClass=*)";
string[] attributesToReturn = new string[] { "description",
"ou", "objectClass" };

PageResultRequestControl pageRequestControl =
new
PageResultRequestControl(pageSize);

//1. Try 1, making the control false
//pageRequestControl.IsCritical = false;

//2. Try 2, Using generic control, how do we specify the pagesize?
//byte[] pageValue =
// BitConverter.GetBytes(5);
//DirectoryControl genericDirectoryControl
// = new DirectoryControl("1.2.840.113556.1.4.319",
pageValue, false, true);

// used to retrieve the cookie to send for the subsequent request
PageResultResponseControl pageResponseControl;
SearchResponse searchResponse;

// create a search request: specify baseDn,
// ldap search filter, attributes to return and scope of the
search
SearchRequest searchRequest = new SearchRequest
(targetOU,
ldapSearchFilter,
SearchScope.Subtree,
attributesToReturn);

// attach a page request control to retrieve the results in
small chunks
searchRequest.Controls.Add(pageRequestControl);

int pageCount = 0;
int count;

// search in a loop untill there is no more page to retrieve
while (true)
{
pageCount++;
searchResponse =
(SearchResponse)ldapConnection.SendRequest(searchRequest);

Console.WriteLine("\r\nPage" + pageCount + ": " +
searchResponse.Entries.Count + " entries:");

// print the entries in this page
count = 0;
foreach (SearchResultEntry entry in searchResponse.Entries)
{
Console.WriteLine(++count + ":" +
entry.DistinguishedName);
}

// retrieve the cookie
if (searchResponse.Controls.Length != 1 ||
!(searchResponse.Controls[0] is PageResultResponseControl))
{
Console.WriteLine("The server did not return a " +
"PageResultResponseControl as
expected.");
return;
}

pageResponseControl =
(PageResultResponseControl)searchResponse.Controls[0];

// if responseControl.Cookie.Length is 0 then there
// is no more page to retrieve so break the loop
if (pageResponseControl.Cookie.Length == 0) break;

// set the cookie from the response control to retrieve the
next page
pageRequestControl.Cookie = pageResponseControl.Cookie;
}

Console.WriteLine("\r\nPaged search is completed
successfully.\r\n");
}
catch(Exception e)
{
Console.WriteLine("\r\nUnexpected exception occured:\r\n\t" +
e.GetType().Name + ":" + e.Message);
}
}
***************

eduard....@gmail.com

unread,
May 31, 2007, 8:24:35 AM5/31/07
to
You should add this line to your code:

ldapConnection.SessionOptions.ProtocolVersion = 3;

right after

ldapConnection.Bind(credential);

That did it for me.

On Apr 6, 8:38 am, Dattesh Lotlikar

> > "Dattesh Lotlikar" <DatteshLotli...@discussions.microsoft.com> wrote in
> > messagenews:4993E9D8-BEF8-49CD...@microsoft.com...

0 new messages