473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Active Directory Query in ASP

maxamis4
295 Expert 100+
Folks

I have found a code that I am trying to use to query active directory. The code executes without a problem so I am assuming the syntax works. My problems is that a variable I am using does not retain its value. In the AD query it shows up blank, which really puzzles me. See the code I have created below from an article I found that was posted.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ LANGUAGE=VBSCRIPT %>
  3. <%Option Explicit%>
  4.  
  5. <%
  6.     Function getADUserInfo(strUID)
  7.         Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN, strLastLogin, strSid, strBase        
  8.         'on error resume next
  9.         strGeneralLookupError = false
  10. strUID = "UserName"
  11.  
This is the statement that returns an empty value.
Expand|Select|Wrap|Line Numbers
  1. strBase = "<LDAP://DC=subdomain,DC=subdomain,DC=primarydomain,DC=masterdomain>
Expand|Select|Wrap|Line Numbers
  1.         response.write strbase
  2.         strFilter = "(&(objectCategory=person)(objectClass=user)(SAMAccountName=*" & strUID & "))"        
  3.         strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
  4.         'strAttributes = "cn, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
  5.         strScope = "subtree"    
  6.         strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
  7.  
  8.  
  9.     response.write strfullcommand
  10.  
  11.         set rsADUserInfo = Server.CreateObject("ADODB.Recordset")
  12.         set    rsADUserInfo = connAD.Execute(strFullCommand)
  13.         if err.number <> 0 then
  14.             strGeneralLookupError = true
  15.         end if
  16.         set getADUserInfo = rsADUserInfo
  17.         set rsADUserInfo = Nothing
  18.     End Function
  19.  
  20.     Sub getUserData(p_strUserID)
  21.         'on error resume next
  22.         set rsUserData = Server.CreateObject("ADODB.Recordset")
  23.         set rsUserData = getADUserInfo(p_strUserID)
  24.         if not rsUserData.EOF then
  25.             strUserGN = rsUserData("givenName")
  26.             strUserSN = rsUserData("sn")
  27.             strUserOU = rsUserData("company")
  28.             strUserEmail = rsUserData("mail")
  29.             strUserPhone = rsUserData("telephoneNumber")
  30.         else
  31.             strADLookupSuccess = false
  32.         end if
  33.         rsUserData.Close
  34.         set rsUserData = Nothing
  35.     End Sub
  36.  
  37.     'on error resume next
  38.  
  39.     response.expires = 0
  40.  
  41.     DIM connAD, rsUserData, rsADUserInfo
  42.     DIM strUserGN, strUserSN, strUserOU, strUserEmail, strUserPhone
  43.     DIM strBase, strFilter,strAttributes, strScope, strFullCommand
  44.     DIM strGeneralLookupError, strADLookupSuccess
  45.     DIM strUserID
  46.  
  47.     strUserGN = "The user can not be found in the system."
  48.     strGeneralLookupError = false
  49.     strADLookupSuccess = true
  50.  
  51.     set connAD = Server.CreateObject("ADODB.Connection")
  52.     connAD.Provider = "ADsDSOObject"
  53.     connAD.Open "Active Directory Provider"
  54.  
  55.     strUserID = "JuanPGomez"
  56.     call getUserData(strUserID)
  57.  
  58.     connAD.Close
  59.     set connAD = Nothing
  60. %>
  61.  
  62. <html>
  63. <head>
  64.     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  65.     <title>ASP Code to access AD with LDAP Page</title>
  66. </head>
  67.     <body>
  68.         <%=strUserGN%>&nbsp;
  69.         <%=strUserSN%><br />
  70.         <%=strUserOU%><br />
  71.         <%=strUserEmail%><br />
  72.         <%=strUserPhone%><br />
  73.     </body>
  74. </html>
  75.  
Oct 9 '11 #1
0 1720

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ran Davidovitz | last post by:
Hi. We need to create a view of our active directory users (we have 2500). I found out that there is max page size of 1000, so we cannot get more data. Anyone found a solution to that...
0
by: JasonM | last post by:
Help! I'm new to C# and am having trouble with the following code: ..... DirectoryEntry root = new DirectoryEntry("LDAP://<DOMAIN>"); DirectorySearcher searcher = new DirectorySearcher(root);...
3
by: mpriem | last post by:
Hi, I am trying to enumerate Exchange Admin groups, but fail to with the folowing code. Can someone help me with this issue. The executing user has sufficient permissions. using System; ...
1
by: Arvind P Rangan | last post by:
Hi, How do u interpret a Active Directory Structure into code format. Like i have a ADS Structrue like this main.domain.com + AB + UB + AC All my information are in AC
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: Tash | last post by:
I am having a weird problem. I am trying to use the following code to query active directory. Function IsExistInAD(ByVal loginName As String) As Boolean Dim userName As String =...
0
by: Chung Leong | last post by:
In this brief tutorial I'll describe how you retrieve information from an Active Directory through the OLE-DB extension. While it is possible to use the LDAP extension to achieve the same goal, as...
0
by: dug04 | last post by:
Hi I am trying to write a query that will select all users in the Organization bucket in active directory. The problem is that within the Organization bucket, there are many other buckets. I...
7
by: kooch54 | last post by:
I am trying to write a script to simply query the group members in an active directory group. I need to use LDAP to make sure I capture any global global group nestings that may occur. I already...
3
by: =?Utf-8?B?YXppZWdsZXI=?= | last post by:
Hello, everybody. I'd like to do this: For a big program (a web service) I need information about the usergroups an active-directory-user is member of. To be more precise, I need to know if a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.