Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Exchange Server, ASP and ADSI / LDAP

0.00/5 (No votes)
5 May 2004 1  
How to access 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.

Access to the LDAP directory of Exchange

First of all, it must be assured that the internet user has got access to the LDAP directory.

The read access via ADSI to an object in the directory tree takes place with the GetObject method:

StrServer = "Exchange01"
Set cont = GetObject("LDAP://" & strServer)
For Each obj in cont
   Response.Write obj.Name & "<BR>"
Next

The root of the LDAP of Exchange contains the different locations of the company. The contents of this container can be displayed via the FOR-NEXT loop. StrServer is the name of the exchange server on the network.

After displaying the different locations, the Exchange users of the different locations can be displayed in the next step.

To accomplish this, the root must be known. In this specific case, it is "o=BSP".

strServer = "Exchange01"
strOrganisation = "o=BSP"
strLocation = "ou=Mannheim"

Set cont = GetObject("LDAP://" & strServer &"/cn=Recipients,"_
           & strLocation & "," & strOrganisation)
For Each obj in cont
   Response.Write & obj.Name & "<BR>"
Next

This means an access to the container "cn= Recipients", which contains the data of the exchange users. With the For-NEXT loop, the individual objects of this container, i.e. the users, can be displayed.

Now that the single users are known, their attributes can be displayed:

strServer = "Exchange01"
strOrganisation = "o=BSP"
strLocation = "ou=Mannheim"
strUser = "cn=ckiefer"
Set objMailbox = GetObject("LDAP://" & strServer &"/" &strUser& ",_
   cn=Recipients," & strLocation & "," & strOrganisation)
response.write "<table border=1>"
response.write "<tr><td colspan=""2"">Userdetails</td></tr>"
response.write "<tr><td>name</td><td>" & objMailbox.name & "</td></tr>"
response.write "<tr><td>mail</td><td>" & objMailbox.mail & "</td></tr>"
response.write "<tr><td>cn</td><td>" & objMailbox.cn & "</td></tr>"
response.write "<tr><td>sn</td><td>" & objMailbox.sn & "</td></tr>"
response.write "<tr><td>givenname</td><td>" & objMailbox.givenname & "</td></tr>"
response.write "<tr><td>member</td><td>" & objMailbox.member & "</td></tr>"
response.write "<tr><td>department</td><td>" & objMailbox.department & "</td></tr>"
response.write "<tr><td>title</td><td>" & objMailbox.title & "</td></tr>"
response.write "<tr><td>uid</td><td>" & objMailbox.uid & "</td></tr>"
response.write "<tr><td>company</td><td>" & objMailbox.company & "</td></tr>"
response.write "<tr><td>telephonenumber</td><td>" &_
   objMailbox.telephonenumber & "</td></tr>"
response.write "<tr><td>facsimiletelephonenumber</td><td>" &_
   objMailbox.facsimiletelephonenumber & "</td></tr>"
response.write "<tr><td>postaladdress </td><td>" &_
   objMailbox.postaladdress & "</td></tr>"
response.write "<tr><td>homepostaladdress </td><td>" &_
   objMailbox.homepostaladdress & "</td></tr>"
response.write "<tr><td>physicalDeliveryOfficeName</td><td>"_
   & objMailbox.physicalDeliveryOfficeName & "</td></tr>"
response.write "</table>"

If you put these functions together, you can write an ASP script which allows you to display the entries of the Exchange address book.

Download the complete script 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