ASP <-> LDAP

F

Fabian Baum

Hi,

i have a problem in the following source code, i cant read the department
from the AD ;(
where is my mistake?

Dim strBrowser 'Brausertyp

If Request.ServerVariables("LOGON_USER") = "" Then
Response.Status = "401 Unauthorized"
Response.End
End If

Dim strUserADsPath 'ADSI user ads path
Dim objUser 'ADSI user object
Dim strADSPath 'ADS path

Dim strUserID 'User Name
Dim strUserDomain 'User Domain
Dim intSlash 'Hilfsvariable zum trennen von Domain und User
Dim strSpath 'Suchpfad im AD

Dim rs 'ADODB Recordset
Dim con 'Handle zur ADODB Verbindung
Dim ocommand 'ADODB Query Command

Dim strVorname
Dim strNachname
Dim strEmail
Dim strKostenstelle

strUserAdsPath = Request.ServerVariables("LOGON_USER")

intSlash = instr(1,strUserAdsPath,"\")

strUserDomain = mid(strUserAdsPath,1,intSlash -1 )
strUserID = mid(strUserAdsPath,intSlash + 1 ,(len(strUserAdsPath)))


strSpath = "LDAP://dc=" & strUserDomain & ",dc=domain,dc=com"


'ADO Connection object
Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"

'ADO Command object
Set ocommand = CreateObject("ADODB.Command")
ocommand.ActiveConnection = con
ocommand.CommandText = "<" & strSpath &
">;(&(objectCategory=person)(objectClass=user)(givenName=Fabian)(sn=Baum));a
dsPath,name,ou;subTree"

Set rs = ocommand.Execute


Do While Not(rs.EOF)

' Connecten zum User im AD
strUserADsPath = rs.Fields(0).value

set objUser = GetObject(strUserADsPath)

strVorname = objUser.givenName
strNachname = objUser.sn
strEmail = objUser.mail
strKostenstelle = objUser.description
strNTUser = objUser.cn
strAbteilung = objUser.department

Response.Write "<br>SN: " & objUser.department

rs.MoveNext
loop
Set objUser = Nothing

set con = Nothing
set ocommand = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top