我有一個運行在帶有IIS 6的Windows 2003上的ASP經典Intranet站點。在你問爲什麼它是一個站點之前,我繼承了這個站點並且目前它不能被更改。我試圖轉換一部分網站,查找舊數據庫中需要消除的內容,而不是在AD中查找用戶,並根據他們是否是安全組成員來授予權限。我使用VBscript在AD中搜索用戶並獲取其組成員身份的代碼。我的問題似乎是在IIS中的雙跳或權限問題,阻止我。這裏是我的代碼:ASP經典活動目錄查詢權限問題。 ASP錯誤80072020
<%
Dim sLogonUser : sLogonUser = Request.ServerVariables("Logon_User")
Dim sDomain : sDomain = Mid(sLogonUser, 1, Instr(1, sLogonUser, "\") - 1)
Dim sLogonName : sLogonName = Mid(sLogonUser, Instr(1, sLogonUser, "\") + 1)
response.write sDomain
response.write sLogonName
' Create ADO connection to Active Directory
'
Dim oConnection
Set oConnection = CreateObject("ADODB.Connection")
With oConnection
.Provider = "ADsDSOObject"
.Mode = "1" 'Read
.Properties("Encrypt Password") = True
.Open "Active Directory Provider"
End With
' Create command to search user in Active Directory
'
Dim oCommand
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
' Build the ADsPath element of the CommandText
'
Dim oRoot
Dim oDomain
Dim sADsPath
Dim sFilter
Dim sAttribsToReturn
Dim sDepth
Dim oRS
Dim i
Dim value
Dim c_EmployeeDirectoryConnectionString
Set oRoot = GetObject("LDAP://" & sDomain & "/rootdse")
Set oDomain = GetObject("LDAP://" & sDomain & "/" & oRoot.Get("defaultNamingContext"))
sADsPath = "<" & oDomain.ADsPath & ">"
' Build the filter element of the CommandText
'
sFilter = "(&(objectCategory=Person)(objectClass=user)(sAMAccountName=" & sLogonName & "))"
' Build the returned attributes element of the CommandText
'
sAttribsToReturn = "distinguishedName,memberOf"
' Build the depth element of the CommandText
'
sDepth = "subTree"
' Assemble the CommandText
'
ocommand.CommandText = sADsPath & ";" & sFilter & ";" & sAttribsToReturn & ";" & sDepth
' Execute the query
'
Set oRS = ocommand.Execute
' Only one user should meet the criteria
'
If (oRS.RecordCount = 1) Then
' Get that user's info
'
oRS.MoveFirst
For i = 0 To oRS.Fields.Count - 1
' memberOf
'
If (oRS.Fields(i).Name = "memberOf") Then
' adVariant
'
For Each value In oRS.Fields(i).Value
if Instr(value, "testgroup") <> 0 then
response.write "member of testgroup"
End If
Next
End If
Next
End If
%>
當你運行你的代碼正確地獲取用戶,但是當它去找一找到AD失敗,出現錯誤:運行在本地當'80072020' <iis site path>/test.asp, line 44
我得到的錯誤在網絡服務器上或遠程從我的機器上。 Web服務器配置了集成的Windows身份驗證。匿名身份驗證已關閉,並且該站點使用作爲域服務帳戶運行的應用程序池標識進行設置。我對IIS知之甚少,但我認爲我的設置有誤。如果我硬編碼一個用戶名並在匿名身份驗證下運行,它會很好地查找用戶。任何幫助或在正確的方向微調將是真棒。