Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Example of ASP LDAP query string? 14

Status
Not open for further replies.

MikeBronner

Programmer
May 9, 2001
756
US
Could someone post an example of ASP code used to query LDAP without any proprietary components?

Thanks! Take Care,
Mike
 
I can connect with no problems...it's only certain attributes like department and memberOf that hose things up.

I can return cn, mail, description, sn, ect. but there are some that return "Unspecified Error" when I include them in the query. I tried using both LDAP and GC...same result. I did find that GC is quicker though.
 
ZColton, I hope theres still a chance you may read this.
Back in Oct 14, 2003 you posted a script having listed the departments with a "distinct" option so as to not list every dept 100 times. I've been trying to do that for a week now and going nutz... the script you posted worked excellent, only I need to do that in a drop down list. I've been working with your script trying to make it work and I give up and turning to you for help.

Thanks
CN
 
CoolNutz,
Think I know what you want... Give me a little time and I'll post it here.

Z
 
All Done:
Code:
<%@ Language=VBScript %>
<%
Option Explicit
response.buffer = true
Dim con,rs,Com,objADsPath,objDomain,objADOU,iLoop,bolFound,strdepartments,rsarray,rowcounter,numrows
strdepartments=&quot;&quot;
%>
<html>
<head>
<title>Phone List</title>
</head>
<body bgcolor=&quot;#CCCCCC&quot; topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>
<%
Set objDomain = GetObject (&quot;GC://rootDSE&quot;)
objADsPath = objDomain.Get(&quot;defaultNamingContext&quot;)
Set objDomain = Nothing
Set con = Server.CreateObject(&quot;ADODB.Connection&quot;)
con.provider =&quot;ADsDSOObject&quot;
con.open &quot;Active Directory Provider&quot;
Set Com = CreateObject(&quot;ADODB.Command&quot;)
Set Com.ActiveConnection = con 
Com.CommandText =&quot;select department from 'GC://&quot;+objADsPath+&quot;' WHERE objectCategory='person' AND department='*' ORDER BY department&quot;
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,&quot;,&quot;)
 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=&quot;&quot; then
   strdepartments=rsarray(0,rowcounter)
   Else
    strdepartments=strdepartments&&quot;,&quot;&rsarray(0,rowcounter)
  End If
 End If
NEXT

dim deparray
deparray=split(strdepartments,&quot;,&quot;)
%>
<form>
  <p><select size=&quot;1&quot; name=&quot;department&quot;>
    <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>
 
Hi,

Im very new at asp and LDAP.

My scenario: A user opens an .asp page and some fields get populated with thier information taken from exchange server.

What im doing:
I know how to get a logon name of the local user.

1 - Im trying to search for LDAP servers on my network.
Then select the correct LDAP server (exchange server?)
2 - then in the server use the logon name to get the object that contains the attibutes of the logon user.

populating the field i know but i dont know how to do the LDAP stuff.

Can anyone help?
 
Describe your network:
Win2k?
Exchange 2K?
We need a little more info.
 
oh sorry i forgot
yeah win2k and exchange 2k.

im currently trying to test out your phonebook example.
im looking at the code whre u dont have to hard code the server name.

Is is possible to do that example using LDAP?
Also im not familiar with what objects in exchange 2k has the attributes of the users


Thanks for your help.
 
So let me see if I understand:
You want to display user account info about the currently logged in user.
What info do you want to display?
 
On my asp form i want to populate; user real name, phone extention, email address into separate text fields.

So when the user accesses this page it will automatically fill in those information. This asp page is part of our service desk request form.

i could post my form if you would like to see it
 
All done:


Code:
<%@ Language=VBScript %>
<%
Option Explicit
Dim strUsername,con,rs,Com,objADsPath,objDomain,name,telephonenumber,mail
%>
<html>
<head>
</head>
<body>
<%
strUsername = Request.ServerVariables(&quot;auth_user&quot;)
strUserName = Right(strUserName, Len(strUserName) - InStrRev(strUserName, &quot;\&quot;))
Set objDomain = GetObject (&quot;GC://rootDSE&quot;)
objADsPath = objDomain.Get(&quot;defaultNamingContext&quot;)
Set objDomain = Nothing
Set con = Server.CreateObject(&quot;ADODB.Connection&quot;)
con.provider =&quot;ADsDSOObject&quot;
con.open &quot;Active Directory Provider&quot;
Set Com = CreateObject(&quot;ADODB.Command&quot;)
Set Com.ActiveConnection = con
Com.CommandText =&quot;select name,telephonenumber,mail FROM 'GC://&quot;+objADsPath+&quot;' where sAMAccountname='&quot;+strUsername+&quot;'&quot;
Set rs = Com.Execute
name=rs(&quot;name&quot;)
telephonenumber=rs(&quot;telephonenumber&quot;)
mail=rs(&quot;mail&quot;)
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
response.write name&&quot;<br>&quot;
response.write telephonenumber&&quot;<br>&quot;
response.write mail&&quot;<br>&quot;
%>
</body>
</html>
 
Thanks alot. you are very helpful. I want to get u some coffee. :)

I have a question.
Request.ServerVariables(&quot;LOGON_USER&quot;)

when using that line, i ran it locally on my computer and it did not pick up any value. Why is that?
 
What authentication methods are you using for this web page?
 
im not sure. how could i found out? should i ask my network admin.

this webpage is accessed internally on our intranet
 
To populate the server variable &quot;LOGON_USER&quot; anonymous access must be removed. It will only work with basic or intergrated windows authentication.
 
Is that why you used auth_user? Since it is able to retrieve the user regardless of anonymous access?
 
GC is global catalog
searching the GC is faster that LDAP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top