2.2 How to Use LDAP Libraries for C#

An application generally uses the following procedure to utilize LDAP libraries for C#:

  1. SSL Integration: Integrate the Mono Security Library with the LDAP libraries for C#. For integrating instructions, refer to Section 1.5.3, Integrating the LDAP Libraries for C#.

  2. Establish an LDAP Connection: Initialize an LDAP session with a directory server. The LdapConnection.Connect() call establishes a handle to the session, allowing multiple sessions to be open at the same time, on different instances of LdapConnection.

  3. Authenticate to the LDAP Server: Authenticate to the LDAP server with LdapConnection.Bind().

  4. Perform LDAP Operations and Obtain Results: The synchronous version of LdapConnection.Search() returns an LdapSearchResults, which can be enumerated to access all entries found. The asynchronous version of LdapConnection.Search() returns an LdapSearchQueue, which is used to read the results of the search. LdapConnection.Read() returns a single entry.

  5. Close the Connection: Close the connection. The LdapConnection.Disconnect() call closes the connection.