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

Exchange Server, ASP and ADSI / LDAP

By , 5 May 2004
Rate this:
Please Sign up or sign in to vote.

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

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

 
QuestionWhat is strOrganisation = "o=BSP"?? Pinmemberzenjohn1-Nov-06 14:16 
QuestionLDAP query slows down too long Pinmemberemmpergul1-Aug-06 10:02 
QuestionWhere is index_exchange.asp? Pinmemberpguths24-Nov-05 7:55 
AnswerRe: Where is index_exchange.asp? PinmemberChristian Kiefer30-Nov-05 21:15 
GeneralLDAP:// protocol in web browser Pinmembercacadeperro31-Oct-05 11:38 
GeneralRe: LDAP:// protocol in web browser PinmemberChristian Kiefer31-Oct-05 23:20 
Questionwhere is the exchange server? Pinmemberexplosure99914-Aug-05 23:17 
GeneralWHY IS IT SOOO HARD TO GET A CODE SAMPLE THAT JUST WORKS?????????????/ PinmemberAaron3118-Jul-05 16:29 
GeneralRe: WHY IS IT SOOO HARD TO GET A CODE SAMPLE THAT JUST WORKS?????????????/ PinmemberChristian Kiefer26-Jul-05 22:18 
GeneralExchange 5.5 PinmemberOfflinesurfer30-Sep-04 11:46 
GeneralRe: Exchange 5.5 PinmemberChristian Kiefer28-Oct-04 22:40 
Generalselect box is empty Pinmemberlizm10023-Jul-04 5:50 
GeneralRe: select box is empty PinsussAnonymous8-Oct-04 1:20 
GeneralThank you PinmemberThomas Felting10-May-04 22:46 

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.140415.2 | Last Updated 6 May 2004
Article Copyright 2004 by Christian Kiefer
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid