LDAP + ASP 经典 + ADODB = 2147217865。(使用 LDAP 与 ASP Classic 中的 Active Directory 对话。错误:2147217865)

发布于 2024-09-26 21:37:28 字数 3031 浏览 1 评论 0原文

我需要使用 LDAP 对旧 ASP 网站的用户进行身份验证。

我一直在使用找到的代码

它看起来像这样:

<%@ 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>

我可以使用 C# 拉回信息,所以我不认为是服务器导致了问题。

我最终得到的只是 2147217865 错误。

AD服务器是Windows Server 2003。Web

服务器是XP Pro上的IIS。

我尝试将 strFullCommand 更改为:

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

那里没有骰子。有什么想法吗?

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%> 
<%=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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稀香 2024-10-03 21:37:28

这有效:

function AuthenticateUser(UserName, Password, Domain)
dim strUser
' assume failure
AuthenticateUser = false

strUser = UserName
strPassword = Password

strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password") = strPassword
oConn.Properties("Encrypt Password") = true
oConn.open "DS Query", strUser, strPassword

set cmd = server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery
on error resume next
set oRS = cmd.Execute
if oRS.bof or oRS.eof then
    AuthenticateUser = false
else
    AuthenticateUser = true
end if
set oRS = nothing
set oConn = nothing

end function

This works:

function AuthenticateUser(UserName, Password, Domain)
dim strUser
' assume failure
AuthenticateUser = false

strUser = UserName
strPassword = Password

strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password") = strPassword
oConn.Properties("Encrypt Password") = true
oConn.open "DS Query", strUser, strPassword

set cmd = server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery
on error resume next
set oRS = cmd.Execute
if oRS.bof or oRS.eof then
    AuthenticateUser = false
else
    AuthenticateUser = true
end if
set oRS = nothing
set oConn = nothing

end function
你爱我像她 2024-10-03 21:37:28

要调试此问题,我要做的第一件事就是删除那些 On Error Resume Next 语句。他们可能隐藏了许多你没有看到的罪恶报道。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文