How To Render the Global Address List with ADSI (241474)



The information in this article applies to:

  • Microsoft Active Directory Service Interfaces 2.5
  • Microsoft Active Directory Service Interfaces 1.0
  • Microsoft Active Directory Service Interfaces 2.0

This article was previously published under Q241474

SUMMARY

This article demonstrates how to display the Microsoft Exchange Global Address List (GAL) using Active Directory Services Interfaces (ADSI).

MORE INFORMATION

In order to render the GAL using ADSI in an Active Server Page (.asp), you must have the following software installed on your Microsoft Windows NT network.
  • Microsoft Exchange Server 5.5
  • ADSI 2.5 (recommended)
  • Internet Information Server
Use the following steps for implementation:
  1. Copy the following code sample into your .asp file.
  2. Change any reference to "MyServer" with the name of the target Microsoft Exchange Server.
  3. Open the .asp file in your client browser to view the results.

In this sample ADSI uses an OLEDB provider and Lightweight Directory Access Protocol(LDAP) to retrieve information from the Exchange directory. For information about building ADO queries for ADSI, please click the article number below to view the article in the Microsoft Knowledge Base:

187529 How To Using ADO to Access Objects Through ADSI LDAP Provider

<HTML>
<BODY>
<CENTER><H2>Global Address List</H2><CENTER>
<TABLE ALIGN=RIGHT>
<TR>
 <TD>Mailboxes<TD BGCOLOR=RED>&nbsp &nbsp &nbsp</TD>
<TR>
 <TD>Distribution Lists<TD BGCOLOR=GREEN>&nbsp &nbsp &nbsp</TD>
<TR>
 <TD>Custom Recipients<TD BGCOLOR=BLUE>&nbsp &nbsp &nbsp</TD>
<TR>
</TABLE>
<%
   'TO DO : Change the below name to your Exchange server name
   '
   ' Note if you want to use NT Challenge Response authentication this
   ' will need to be the same machine as the ASP is running on
   strServerName = "MyServer"
   strUser = Request.ServerVariables("LOGON_USER") 'retrieve the user 
   if strUser = "" then
     Response.Write "You are using Anonymous authentication you will need to change it so the user can be identified"
     Response.End
   end if

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

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

   set oCommand.ActiveConnection = oConn  'set the active connection

 ' Next we will build the LDAP query that will be used to retrieve the contents of the GAL.  
 ' We will specify which server we want to run the query against,
 ' a filter for what types of objects we are looking for, the attributes we would like
 ' returned, and the type of search
 ' A filter of (objectClass=person) will return mailboxes, distribution lists, and custom recipients

   strQuery= "<LDAP://" & strServername & ">;(objectClass=person);cn,telephoneNumber,physicalDeliveryOfficeName,title,company,objectClass,uid;subtree"
   oCommand.CommandText = strQuery
   oCommand.Properties("Page Size") = 99   'a paged query is used to avoid Exchange LDAP server limits
   set oRS = oCommand.Execute   'Execute the query

' Now we will loop through the results of our query 
'   and build a table to display the Global Address List
 
   %>
   <TABLE BORDER=3>
   <TR>
   <TH>Display Name<TH>Phone<TH>Office<TH>Title<TH>Company<TH>Alias
   <%
   While not oRS.EOF
   %>
     <TR>
    <%
    ' Get the class of the object and set the appropriate color
    vObjectClass=oRS.Fields("objectClass")
    select case  vObjectClass(0)
      case "organizationalPerson" 
          strColor = "RED"
      case "groupOfNames" 
          strColor = "GREEN"
      case "Remote-Address" 
          strColor = "BLUE"
      case else
        ' other may include mailbox agents, Public folders, etc.
          strColor = "BLACK"
     end select
     %>
     <TD><FONT COLOR=<%=strColor%>><%=oRS.Fields("cn")%></FONT>
     <TD><%=oRS.Fields("telephoneNumber")%>
     <TD><%=oRS.Fields("physicalDeliveryOfficeName")%>
     <TD><%=oRS.Fields("title")%>
     <TD><%=oRS.Fields("company")%>
     <TD><%=oRS.Fields("uid")%>
     
   <%
   oRS.MoveNext
   wend
   %>
   </TABLE>
</BODY>
</HTML>
				

REFERENCES

For additional information on ADSI, please see the following Web site:
For information about rendering the Global Address List with Collaboration Data Objects, please click the article number below to view the article in the Microsoft Knowledge Base:

192436 How To Render the Global Address List with CDO


Modification Type:MinorLast Reviewed:7/15/2004
Keywords:kbhowto kbMsg KB241474