代码之家  ›  专栏  ›  技术社区  ›  NitroxDM

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

  •  1
  • NitroxDM  · 技术社区  · 16 年前

    我需要使用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#收回信息,所以我认为不是服务器造成了问题。

    广告服务器是Windows server 2003。

    web服务器是XP Pro上的IIS。

    我已尝试将strFullCommand更改为:

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

    2 回复  |  直到 16 年前
        1
  •  2
  •   NitroxDM    15 年前

    这项工作:

    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
  •  1
  •   erlando    16 年前

    On Error Resume Next 声明。他们可能隐藏了很多你没有看到的罪过。