views:

31

answers:

1

I need to use LDAP to authenticate users for an old ASP website.

I have been using the code found here.

It looks like this:

<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>

<%
Function getADUserInfo(strUID)
    on error resume next
    strGeneralLookupError = false
    strBase = "<LDAP://DC=[DOMAIN], DC=[DOMAIN EXETENTION]>"
    strFilter = "(sAMAccountName=" & strUID & ")" 
    strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
    'strAttributes = "cn, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"
    strScope = "subtree"    
    strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
    set rsADUserInfo = Server.CreateObject("ADODB.Recordset")
    set rsADUserInfo = connAD.Execute(strFullCommand)
    if err.number <> 0 then
        strGeneralLookupError = true
    end if
    set getADUserInfo = rsADUserInfo
    set rsADUserInfo = Nothing
End Function

Sub getUserData(p_strUserID)
    on error resume next
    set rsUserData = Server.CreateObject("ADODB.Recordset")
    set rsUserData = getADUserInfo(p_strUserID)
    if not rsUserData.EOF then
        strUserGN = rsUserData("givenName")
        strUserSN = rsUserData("sn")
        strUserOU = rsUserData("company")
        strUserEmail = rsUserData("mail")
        strUserPhone = rsUserData("telephoneNumber")
    else
        strADLookupSuccess = false
    end if
    rsUserData.Close
    set rsUserData = Nothing
End Sub

on error resume next

response.expires = 0

DIM connAD, rsUserData, rsADUserInfo
DIM strUserGN, strUserSN, strUserOU, strUserEmail, strUserPhone
DIM strBase, strFilter,strAttributes, strScope, strFullCommand
DIM strGeneralLookupError, strADLookupSuccess
DIM strUserID

strUserGN = "The user can not be found in the system."
strGeneralLookupError = false
strADLookupSuccess = true

set connAD = Server.CreateObject("ADODB.Connection")
connAD.Provider = "ADsDSOObject"
connAD.Properties("User ID") = "[DOMAIN]\[USERNAME]" ' ### remember to make sure this user has rights to access AD
connAD.Properties("Password") = "[PASSWORD]"
connAD.Properties("Encrypt Password") = true
connAD.Open

strUserID = "[USERNAME YOU WANT INFO FOR]"
call getUserData(strUserID)

connAD.Close
set connAD = Nothing
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ASP Code to access AD with LDAP Page</title>
</head>
<body>
<%=strUserGN%>&nbsp;
<%=strUserSN%><br />
<%=strUserOU%><br />
<%=strUserEmail%><br />
<%=strUserPhone%><br />
</body>
</html>

I can pull back info using C# so I don't think it's the server that is causing the issue.

All I end up with is a 2147217865 error.

The AD server is Windows Server 2003.

The web server is IIS on XP Pro.

I have tried changing strFullCommand to:

Select cn From 'LDAP://SEVERPATH' where objectClass='user'" & " and objectcategory='person'

No dice there. Any ideas?

A: 

The first thing I'd do to debug this is get rid of those On Error Resume Next statements. They could be hiding a multitude of sins that you're not seeing properly reported.

Kev
No change. I get the same error.
NitroxDM

related questions