我将以下代码用于 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