到目前为止,这个问题只有 7 次浏览,并为我赢得了“风滚草”徽章,但我认为我会跟进我的最终解决方案。
使用 CatAdm 对象确实是最终的唯一选择,因为这是解决索引服务中与别名相关的错误的唯一方法(在我的原始帖子中提到)。
一种方法(在 ASP.NET 中相对简单,在 ASP Classic 中使用等效的自定义 COM 组件可能)是使用模拟:使用特权帐户从 CatAdm 读取范围列表对象,然后使用授权的 HTTP 请求的帐户对这些范围进行查询。结果将仅包含该帐户有权访问的目录。
问题在于只有管理员帐户才有权使用 CatAdm 对象,从安全角度来看,使用管理员帐户来处理 HTTP 请求并不是一个好的做法。
因此,尽管它增加了管理负担,但我决定编写一个单独的 HTA 脚本,无论何时从目录中添加或删除目录,都必须运行该脚本(在服务器机器本身上,而不是通过 HTTP)。该脚本从 CatAdm 对象中读取范围列表并将其写入配置文件:
Function makeConfig(catalogName)
Set machine = CreateObject("Shell.LocalMachine")
Set adm = CreateObject("Microsoft.ISAdm")
Set cat = adm.GetCatalogByName(catalogName)
Dim config
config = "<%" & vbCrLf
config = config & "' Automatically generated by " & document.location.pathname & " at " & Now & vbCrLf
config = config & "' This file is indended for inclusion by the intranet search script." & vbCrLf
config = config & "catalogMachine = """ & machine.MachineName & """" & vbCrLf
config = config & "catalogName = """ & catalogName & """" & vbCrLf
scopeFound = cat.FindFirstScope()
While scopeFound
Set scope = cat.GetScope()
If Not scope.ExcludeScope Then
' Must be lowercase because query results are returned in lowercase
dir = lcase(scope.Path)
If scope.Alias <> "" Then
alias = scope.Alias
Else
alias = scope.Path
End If
config = config & "dirs(""" & dir & """) = """ & alias & """" & vbCrLf
End If
scopeFound = cat.FindNextScope()
Wend
config = config & "%>" & vbCrLf
makeConfig = config
End Function
然后搜索脚本本身只是读取配置文件并使用它来查找可访问目录的列表。要解决索引服务错误,需要从物理目录映射到别名:
Set dirs = CreateObject("Scripting.Dictionary")
%><!--#include file="search_config.asp"--><%
catalogURI = "query://" & catalogMachine & "/" & catalogName
queryString = ""
For Each dir In dirs
If queryString <> "" Then
queryString = queryString & " or "
End If
queryString = queryString & "@Path = """ & dir & """"
Next
' But the @Path attribute is not indexed, and running queryString
' as is will return no results. Solution: limit search to only
' directories, i.e. items with the 0x10 flag set in @Attrib.
queryString = "@Attrib ^a 0x10 and (" & queryString & ")"
' No point asking for sorted query results, because we need
' to map the results from real paths to network aliases and
' sort again ourselves.
Set query = Server.CreateObject("ixsso.Query")
query.Catalog = catalogURI
query.Query = queryString
query.Columns = "path"
query.MaxRecords = dirs.Count
Set rs = query.CreateRecordSet("sequential")
i = 0
Do While Not rs.EOF
ReDim Preserve accessibleAliases(i)
accessibleAliases(i) = dirs(rs("path").Value)
i = i + 1
rs.MoveNext
Loop
rs.Close
BubbleSort accessibleAliases