MikeBronner
Programmer
Could someone post an example of ASP code used to query LDAP without any proprietary components?
Thanks! Take Care,
Mike
Thanks! Take Care,
Mike
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<%@ Language=VBScript %>
<%
Option Explicit
response.buffer = true
Dim con,rs,Com,objADsPath,objDomain,objADOU,iLoop,bolFound,strdepartments,rsarray,rowcounter,numrows
strdepartments=""
%>
<html>
<head>
<title>Phone List</title>
</head>
<body bgcolor="#CCCCCC" topmargin="0" leftmargin="0">
<%
Set objDomain = GetObject ("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select department from 'GC://"+objADsPath+"' WHERE objectCategory='person' AND department='*' ORDER BY department"
Set rs = Com.Execute
rsarray=rs.getrows
rs.Close
con.close
Set rs = Nothing
Set con = Nothing
numrows=ubound(rsarray,2)
FOR rowcounter=0 to numrows
dim myarray
myarray=split(strdepartments,",")
bolFound = False
For iLoop = LBound(myarray) to UBound(myarray)
If CStr(myarray(iLoop)) = CStr(rsarray(0,rowcounter)) Then
bolFound = True
End If
Next
IF bolFound = False Then
If strdepartments="" then
strdepartments=rsarray(0,rowcounter)
Else
strdepartments=strdepartments&","&rsarray(0,rowcounter)
End If
End If
NEXT
dim deparray
deparray=split(strdepartments,",")
%>
<form>
<p><select size="1" name="department">
<option selected>Select a Department</option>
<%For iLoop = LBound(deparray) to UBound(deparray)%>
<option><%response.write deparray(iLoop)%></option>
<%Next%>
</select></p>
</form>
</body>
</html>
<%@ Language=VBScript %>
<%
Option Explicit
Dim strUsername,con,rs,Com,objADsPath,objDomain,name,telephonenumber,mail
%>
<html>
<head>
</head>
<body>
<%
strUsername = Request.ServerVariables("auth_user")
strUserName = Right(strUserName, Len(strUserName) - InStrRev(strUserName, "\"))
Set objDomain = GetObject ("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select name,telephonenumber,mail FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rs = Com.Execute
name=rs("name")
telephonenumber=rs("telephonenumber")
mail=rs("mail")
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
response.write name&"<br>"
response.write telephonenumber&"<br>"
response.write mail&"<br>"
%>
</body>
</html>