I have an ASP page that uses a VB class to execute a query against
LDAP to capture the email address of the currently logged in domain
user. I initially developed this script on a Windows XP Pro box with
SP2 running IIS 5.1. As soon as I moved the script to one of my web
servers, it failed with an error of the table returned by the LDAP
query being empty (both servers behave identically regarding this
script - one is Windows 2000 Advanced server w/SP4 and the other is
Windows Server 2003 Enterprise w/SP1). It runs fine when I run it as
a standalone vbscript file (making appropriate changes of course) on
the two server machines, but as soon as I try to run it from a web
app, it fails. The sites I am running it from on each web server are
both configured to use Integrated Windows Authentication only, no
anonymous. This is the same configuration I have on my local
development box. Any input would be helpful.
Here is my code...
<%
Class ldapQuery
Private m_curUser, m_strPath, m_strFilter, m_strSuf,
m_strAttribs, m_strScope, m_strADsPath, m_intPathLen
Private m_intUsrLen, m_strProvider, m_strDom, m_intDomLen,
m_objUsr, m_strUsrname, m_objCxn, m_objCmd
Private m_strCmdTxt, m_rsTemp, m_strEmail
Public strFrom
Private Sub Class_Initialize
m_curUser = Request.ServerVariables("AUTH_USER")
strFrom = getEmail(m_curUser)
End Sub
Private Function getEmail(curUser)
curUser = Replace(curUser,"\","/")
Set m_objUsr = GetObject("WinNT://" & curUser)
m_strUsrname = m_objUsr.FullName
getEmail = sendQuery(m_strUsrname)
End Function
Private Function sendQuery(strUser)
m_strPath = Chr(60) & "LDAP://DC=domain,DC=com" & Chr(62)
& ";"
m_strFilter =
"(&(&(objectCategory=person)(objectClass=user)(name="
m_strSuf = ")))"
m_strAttribs = "mail"
m_strScope = "subtree"
Set m_objCxn = Server.CreateObject("ADODB.Connection")
Set m_objCmd = Server.CreateObject("ADODB.Command")
m_objCxn.Provider = "ADsDSOObject"
m_objCxn.Open "Active Directory Provider"
Set m_objCmd.ActiveConnection = m_objCxn
m_strCmdTxt = m_strPath & m_strFilter & strUser & m_strSuf
& ";" & m_strAttribs & ";" & m_strScope
m_objCmd.CommandText = m_strCmdTxt
Set m_rsTemp = m_objCmd.Execute(m_strCmdTxt)
If Not m_rsTemp.EOF Then
sendQuery = m_rsTemp(0)
Else
sendQuery = "not found"
End If
End Function
Private Sub Class_Terminate
Set m_objCxn = Nothing
Set m_objCmd = Nothing
Set m_objUsr = Nothing
Set m_rsTemp = Nothing
End Sub
End Class
Dim tmp
Set tmp = New ldapQuery
Response.Write("<hr />Your username is " &
Request.ServerVariables("AUTH_USER") & "<hr />" & VbCrLf)
Response.Write("<hr />Your email address is " & tmp.strFrom &
".<hr />" & VbCrLf)
Set tmp = Nothing
%>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspClassicAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/