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.
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 manager FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rs = Com.Execute
manager=rs("manager")
rs.Close
managercn=(split((split(manager,",OU="))(0),"="))(1)
managercn=replace(managercn,"\","")
Com.CommandText="select sn,givenName FROM 'GC://"+objADsPath+"' where name='"+managercn+"'"
Set rs = Com.Execute
sn=rs("sn")
givenname=rs("givenName")
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
<%@ Language=VBScript %>
<%
Option Explicit
Dim user,RootDSE,DomainADsPath,Con,Cmd,usrAttributes,usrADOQuery,rs,loginame,manager,managercn,mgrAttributes,mgrADOQuery,mgrsn,mgrgivenname
%>
<html>
<head>
</head>
<body>
<%
user = Request.ServerVariables("Auth_User")
user = Right(user, Len(user) - InStrRev(user, "\"))
Set RootDSE = GetObject("LDAP://RootDSE")
DomainADsPath = RootDSE.Get("defaultNamingContext")
Set RootDSE = Nothing
Set Con = Server.CreateObject("ADODB.Connection")
Con.Provider = "ADsDSOObject"
Con.Open "ADProvider"
Set Cmd = Server.CreateObject("ADODB.Command")
Set Cmd.ActiveConnection = Con
usrAttributes = "givenName,sn,manager"
usrADOQuery = "<LDAP://" & DomainADsPath & ">;(&(objectCategory=person)(objectClass=*)(sAMAccountname=" & user & "));" + usrAttributes + ";subtree"
Cmd.CommandText = usrADOQuery
Set rs = Cmd.Execute
loginame = rs.Fields("givenName") + " " + rs.Fields("sn")
'Session("loginame")=loginame
manager=rs.Fields("manager")
rs.Close
managercn =Left((split(manager,"="))(1),(Len((split(manager,"="))(1))-3))
managercn=replace(managercn,"\","")
mgrAttributes = "givenName,sn"
mgrADOQuery = "<LDAP://" & DomainADsPath & ">;(&(objectCategory=person)(objectClass=*)(name=" & managercn & "));" + mgrAttributes + ";subtree"
Cmd.CommandText = mgrADOQuery
Set rs = Cmd.Execute
mgrsn=rs.Fields("sn")
mgrgivenname=rs.Fields("givenName")
rs.Close
Con.Close
Set rs = Nothing
Set Con = Nothing
response.write mgrsn&"<br>"
response.write mgrgivenname&"<br>"
%>
</body>
</html>