【问题标题】:LDAP + ASP Classic + ADODB = 2147217865. (Using LDAP to talk to Active Directory in ASP Classic. Error:2147217865)LDAP + ASP Classic + ADODB = 2147217865。(在 ASP Classic 中使用 LDAP 与 Active Directory 对话。错误:2147217865)
【发布时间】:2010-10-08 22:51:58
【问题描述】:

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

我一直在使用here找到的代码。

看起来像这样:

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

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

【问题讨论】:

    标签: asp-classic iis-6 ldap windows-server-2003 adodb


    【解决方案1】:

    这行得通:

    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
    

    【讨论】:

      【解决方案2】:

      我要调试它的第一件事是摆脱那些On Error Resume Next 语句。他们可能隐藏了许多你没有看到正确报告的罪行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-28
        • 2014-07-22
        • 1970-01-01
        • 2017-02-27
        相关资源
        最近更新 更多