Click here to Skip to main content
Click here to Skip to main content

User search in the address book of the Exchange Server, with ASP and ADSI / LDAP

, 31 Oct 2004
Rate this:
Please Sign up or sign in to vote.
User search in the address book of the Exchange Server with ASP and ADSI / LDAP.

Introduction

With ADSI (Active Directory Service Interface), Microsoft offers a COM-component for the access to various directory services. ADSI is a component of Windows 2000.

You can think of ADSI as a kind of ODBC-interface for various directory services. In a network, directory services act as an administration of users and capabilities, e.g. computers, printers, users and services.

The structure of a directory service is hierarchic, it can be seen as a directory tree: there is a root where you can start from to other entries. The root can contain containers (knots) and leaves. Containers themselves can contain other entries while leaves mark the end of a branch in a directory tree. Every entry in this directory describes an object and has specific attributes. This can be illustrated with the Windows file system: the hard disk C: is the root, the directories/folders are the containers and the files are the leaves.

Examples for directory systems which are supported by ADSI are: WinNT (access to Windows NT), GC (Windows 2000 Global Catalog), IIS (Internet Information Server Metabase), NWCOMPAT (Novell NetWare 3.x), NDS (Novell NetWare 4.x) and LDAP-directories.

The directory service LDAP will especially be considered in this context. LDAP (Lightweight Directory Access Protocol) was developed at the University of Michigan in the early 90’s and allows an easier access to the directory services of X.500 protocol. LDAP is based on TCP/IP and uses the port number 389. More and more firms integrate LDAP in their products, e.g. Microsoft with its products Exchange, Windows 2000 and Site Server.

Search in the Exchange LDAP directory

With the GetObject method, you can get access to a known object or container in the LDAP directory service, making it possible to display the address book.

But, what can you do if you want to search for a user?

In this case, ADSI offers access to the directory entries via OLE-DB. This makes it possible to make enquiries. Note: access via OLE-DB is only a read access. Entries cannot be modified.

The following information is needed for an LDAP-enquiry:

  • The starting object of the hierarchy of the directory service.
  • Search criteria.
  • Attributes of the found objects which should be returned.
  • Search depth based on the starting object.

The syntax of the LDAP enquiry is:

<LDAP://Servername/Startobject> ; search criteria ; <BR>  returned attributes ; search depth

A characteristic feature of the search criteria is the operators for the definition of the search criteria.

The operators:

  • & - logical “and”
  • | - logical “or”
  • ! - logical “not”
  • = - equal
  • > - bigger than
  • < - smaller than

are put in front of the conditions.

An example: (|(givenname=first name)(sn=surname*)).

The asterisk-symbol (*) can be used as a placeholder for several symbols.

In general, the Exchange Server supports only the use of the asterisk-symbol on the right side. The use of the asterisk-symbol on the left side has to be activated in the Exchange Server under XXXXX first.

There are three possible search depths: BASE (only basic level), ONELEVEL (basic level and first sub level) and SUBTREE (basic level and all following sub levels).

Example: Search in the Exchange LDAP directory

First, an ADO connection to the database is made:

set oConn = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")

oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"

Then an LDAP enquiry is made and send via ADO to the database:

'***Variables and constants
strServerName = "Exchange01"
strName = Request.Form("name")
strLastname = Request.Form("lastname")

strQuery = "<LDAP://" & strServername & _
  ">;(|(sn=" & strLastname & "*)(givenname=" & strName2& "*));*;subtree"

oCommand.CommandText = strQuery
set oRS = oCommand.Execute

If the enquiry was successful, the results will be given back in a RecordSet object. The results can then be displayed with the known ADO methods:

<%
if not oRS.eof then
%>
   <div align="center">
   <table cellpadding="0" border="0" cellspacing="0">
   <tr bgcolor="#C0C0C0">
      <td height="20"><b>Name</b></td>
      <td height="20"><b>Department</b></td>
      <td height="20"><b>Phone</b></td>
      <td height="20"><b>Email</b></td>
   </tr>
   <%While not ors.eof%>
      <tr>
        <td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%></td>
        <td><%=oRS.Fields("department")%></td>
        <td><%=oRS.Fields("telephoneNumber")%></td>
        <td><%=oRS.Fields("mail")%></td>
      </tr>
      <%
      oRS.MoveNext
   wend %>
  </table>
</div>
<%else  
   Response.Write "No item found" 
end if%>

Survey on the user’s attributes in the Exchange LDAP

In Exchange, the following attributes are assigned to every user:

  • Name
  • mail
  • cn
  • sn
  • givenname
  • member
  • department
  • title
  • uid
  • company
  • telephonenumber
  • facsimiletelephonenumber
  • postaladdress
  • homepostaladdress
  • physicalDeliveryOfficeName.

Summary

If you put these components together and add a search mask, then you get an easy search possibility for the Exchange address book, e.g. for the intranet.

Download the file and enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Christian Kiefer
Web Developer
Germany Germany
Christian Kiefer works as a Consultant and developer for internet-software in the middle of Germany.
 
As an Internet specialist, Christian has designed and developed many ASP based applications that take advantage of advanced database and directory services.
 
Christian specializes in advanced Internet technologies such as DHTML, ASP, ADSI, XML, and ASP.NET.

Comments and Discussions

 
Generalone small comment PinmemberJochen_Muenchen27-Jul-06 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 1 Nov 2004
Article Copyright 2004 by Christian Kiefer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid