Click here to Skip to main content
13,897,037 members
Click here to Skip to main content
Add your own
alternative version


45 bookmarked
Posted 10 May 2004

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.


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>
   <%While not ors.eof%>
        <td><%=oRS.Fields("sn")%>, <%=oRS.Fields("givenname")%></td>
   wend %>
   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.


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!


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.

You may also be interested in...

Comments and Discussions

Generalone small comment Pin
Jochen_Muenchen27-Jul-06 2:24
memberJochen_Muenchen27-Jul-06 2:24 
GeneralExchange Server Pin
oskardiazdeleon3-Oct-05 17:24
memberoskardiazdeleon3-Oct-05 17:24 
GeneralUpdate Pin
ehram22-Jul-05 3:57
memberehram22-Jul-05 3:57 
GeneralTable does not exist Pin
Jonathan81465-Jan-05 20:56
memberJonathan81465-Jan-05 20:56 
GeneralRe: Table does not exist Pin
Emileski4-Feb-05 3:19
memberEmileski4-Feb-05 3:19 
GeneralRe: Table does not exist Pin
tesyme622-Feb-05 12:09
membertesyme622-Feb-05 12:09 
GeneralRe: Table does not exist Pin
OlafCoder9-Aug-05 23:38
memberOlafCoder9-Aug-05 23:38 
GeneralRe: Table does not exist Pin
Jonathan814615-Aug-05 3:10
memberJonathan814615-Aug-05 3:10 
AnswerRe: Table does not exist - turnaround Pin
selectric22-Nov-05 6:38
memberselectric22-Nov-05 6:38 
It may be a Security issue
My turn around :

oConn.Open "Ads Provider","username", "password"

Use an allowed user on the LDAP. The ASP server may be OUT of the LDAP.


GeneralError in Script Pin
Member 146004326-Oct-04 1:38
memberMember 146004326-Oct-04 1:38 
GeneralRe: Error in Script Pin
Christian Kiefer28-Oct-04 22:30
memberChristian Kiefer28-Oct-04 22:30 
GeneralI have a few questions about active directory server Pin
sinantrya14-Oct-04 16:37
membersinantrya14-Oct-04 16:37 
GeneralRe: I have a few questions about active directory server Pin
Christian Kiefer28-Oct-04 22:43
memberChristian Kiefer28-Oct-04 22:43 
GeneralCannot find suche_exchange.asp Pin
Hendrie23-May-04 21:57
memberHendrie23-May-04 21:57 
GeneralRe: Cannot find suche_exchange.asp Pin
Christian Kiefer25-May-04 4:47
memberChristian Kiefer25-May-04 4:47 
GeneralRe: Cannot find suche_exchange.asp Pin
Christian Kiefer28-May-04 3:10
memberChristian Kiefer28-May-04 3:10 
GeneralRe: Cannot find suche_exchange.asp Pin
Andrzej Budny17-Sep-04 14:10
memberAndrzej Budny17-Sep-04 14:10 
GeneralRe: Cannot find suche_exchange.asp Pin
Christian Kiefer28-Oct-04 22:29
memberChristian Kiefer28-Oct-04 22:29 
GeneralRe: Cannot find suche_exchange.asp Pin
St3ve22-Nov-04 4:42
memberSt3ve22-Nov-04 4:42 
GeneralRe: Cannot find suche_exchange.asp Pin
Jonathan81465-Jan-05 3:51
memberJonathan81465-Jan-05 3:51 
GeneralRe: Cannot find suche_exchange.asp Pin
St3ve5-Jan-05 3:54
memberSt3ve5-Jan-05 3:54 
GeneralRe: Cannot find suche_exchange.asp Pin
Jonathan81465-Jan-05 4:00
memberJonathan81465-Jan-05 4:00 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190306.1 | Last Updated 1 Nov 2004
Article Copyright 2004 by Christian Kiefer
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid