0

我将以下代码用于 Web ASP.net 应用程序,在本地它可以正常工作,但在服务器上却不行。它返回一个错误说“表不存在”。在我的网络配置中,我提出了<identity impersonate="true"/> 任何想法?

#Region " Get AD ID information from LDAP"
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    Dim objRootDSE, objRecordSet, objCommand, objConnection, strDNSDomain As Object
    Dim strQuery, strBase, strFilter, strAttributes As Object
    Dim intCountNumber As Integer

    Try
        ' Determine DNS domain name from RootDSE object.
        objRootDSE = GetObject("LDAP://RootDSE")
        strDNSDomain = objRootDSE.Get("defaultNamingContext")

        ' Use ADO to search Active Directory.
        objRecordSet = Server.CreateObject("ADODB.recordset")
        objCommand = Server.CreateObject("ADODB.Command")
        objConnection = Server.CreateObject("ADODB.Connection")
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open("Active Directory Provider")
        objCommand.ActiveConnection = objConnection

        strBase = "<LDAP://" & strDNSDomain & ">"
        strFilter = "(&(objectCategory=person)(objectClass=user)(samaccountname=" & TB_UserID.Text & "))"
        strAttributes = "sn,givenname,mail,telephoneNumber,"
        strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
        objCommand.CommandText = strQuery
        objRecordSet = objCommand.Execute
        intCountNumber = objRecordSet.Fields.Count
        TB_Name.Text = objRecordSet.Fields("givenname").value
        TB_LastName.Text = objRecordSet.Fields.Item("sn").value
        TB_Email.Text = objRecordSet.Fields.Item("mail").value
        TB_Telephone.Text = objRecordSet.Fields.Item("telephoneNumber").value

        objRecordSet = Nothing
        objConnection.Close()
    Catch ex As Exception
        DisplayWebMsgBox.WebMsgBox.MessageBox(ex.Message)
    End Try

End Sub

结束区域

4

1 回答 1

0

我发现通过提供程序“ADsDSOObject”,它使用用户信用来运行 LDAP 搜索。因此,除非我提供用户名和密码凭据,否则从服务器端它无法工作。

    objConnection.Properties("User ID") = Username
objConnection.Properties("Password") = Password
 objConnection.Properties("Encrypt Password") = True
于 2012-10-15T13:57:49.633 回答