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
***************
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);
}
}
***************
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...