Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / ASP
Article

Exchange Server, ASP and ADSI / LDAP

Rate me:
Please Sign up or sign in to vote.
3.18/5 (11 votes)
5 May 20042 min read 123.4K   1.1K   32   14
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:

VBScript
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".

VBScript
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:

VBScript
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


Written By
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

 
QuestionWhat is strOrganisation = "o=BSP"?? Pin
zenjohn1-Nov-06 14:16
zenjohn1-Nov-06 14:16 
QuestionLDAP query slows down too long Pin
emmpergul1-Aug-06 10:02
emmpergul1-Aug-06 10:02 
QuestionWhere is index_exchange.asp? Pin
pguths24-Nov-05 7:55
pguths24-Nov-05 7:55 
AnswerRe: Where is index_exchange.asp? Pin
Christian Kiefer30-Nov-05 21:15
Christian Kiefer30-Nov-05 21:15 
GeneralLDAP:// protocol in web browser Pin
Spanish Poop31-Oct-05 11:38
Spanish Poop31-Oct-05 11:38 
GeneralRe: LDAP:// protocol in web browser Pin
Christian Kiefer31-Oct-05 23:20
Christian Kiefer31-Oct-05 23:20 
Questionwhere is the exchange server? Pin
explosure99914-Aug-05 23:17
explosure99914-Aug-05 23:17 
GeneralWHY IS IT SOOO HARD TO GET A CODE SAMPLE THAT JUST WORKS?????????????/ Pin
Aaron3118-Jul-05 16:29
Aaron3118-Jul-05 16:29 
GeneralRe: WHY IS IT SOOO HARD TO GET A CODE SAMPLE THAT JUST WORKS?????????????/ Pin
Christian Kiefer26-Jul-05 22:18
Christian Kiefer26-Jul-05 22:18 
GeneralExchange 5.5 Pin
Offlinesurfer30-Sep-04 11:46
Offlinesurfer30-Sep-04 11:46 
GeneralRe: Exchange 5.5 Pin
Christian Kiefer28-Oct-04 22:40
Christian Kiefer28-Oct-04 22:40 
Generalselect box is empty Pin
lizm10023-Jul-04 5:50
lizm10023-Jul-04 5:50 
GeneralRe: select box is empty Pin
Anonymous8-Oct-04 1:20
Anonymous8-Oct-04 1:20 
GeneralThank you Pin
Thomas Felting10-May-04 22:46
Thomas Felting10-May-04 22:46 

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.