5.1 Supported Controls

The following table contains a list of controls supported in the LDAP libraries for C#.

Table 5-1 Supported Controls

OID

Description

1.2.840.113556.1.4.473

Sever-side sort control request

1.2.840.113556.1.4.474

Server-side sort control response

2.16.840.1.113730.3.4.9

Virtual list view request

2.16.840.1.113730.3.4.10

Virtual list view response

2.16.840.1.113730.3.4.3

Persistent search

2.16.840.1.113730.3.4.7

Entry change notification

2.16.840.1.113730.3.4.2

Manage Dsa IT

The C# code fragments below shows how to use the server side control using the Novell.Directory.Ldap namespace. The code below is hard coded to sort based on the “sn” attribute, and it searches for all objects at the specified searchBase.

Using Sort Control

// C# Library namespace
using Novell.Directory.Ldap;

// Creating an LdapConnection instance
LdapConnection ldapConn= new LdapConnection();

//Connect function will create a socket connection to the server
ldapConn.Connect(ldapHost,ldapPort);

//Bind function will Bind the user object Credentials to the Server
ldapConn.Bind(userDN,userPasswd);

String[] attrs = new String[1];
attrs[0] = "sn";
LdapSortKey[] keys = new LdapSortKey[1];
keys[0] = new LdapSortKey( "sn" );

// Create a LDAPSortControl object - Fail if cannot sort
LdapSortControl sort = new LdapSortControl( keys, true );

// Set the Sort control to be sent as part of search request
LdapSearchConstraints cons = ldapConn.SearchConstraints;

cons.setControls( sort );
ldapConn.Constraints = cons;
LdapSearchResults lsc=ldapConn.Search(searchBase,
LdapConnection.SCOPE_SUB,searchFilter,attrs,false,
LdapSearchConstraints)null );

while (lsc.hasMore())
{
LdapEntry nextEntry = null;

 try
 {
  nextEntry = lsc.next();
 }
 catch(LdapException e)
 {
 Console.WriteLine("Error: " + e.LdapErrorMessage);   
// Exception is thrown, go for next entry
 continue;
 }
Console.WriteLine("\n" + nextEntry.DN);

LdapAttributeSet attributeSet =nextEntry.getAttributeSet();
System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();

while(ienum.MoveNext())
{
LdapAttribute attribute=(LdapAttribute)ienum.Current;
string attributeName = attribute.Name;
string attributeVal = attribute.StringValue;
Console.WriteLine( attributeName + "value:" + attributeVal);
}
}

ldapConn.Disconnect();