现在我们知道了实际的错误是什么,可以得出一个答案。
不允许加载本地资源
是 Chrome 和其他现代浏览器中内置的安全异常。措辞可能不同,但在某种程度上,它们都有安全例外来处理这种情况。
过去您可以覆盖某些设置或应用某些标志,例如
--disable-web-security --allow-file-access-from-files --allow-file-access
在 Chrome 中 (参见 https://stackoverflow.com/a/22027002/692942)
它的存在是有原因的
尽管在这一点上值得指出,这些安全异常的存在是有充分理由的,试图规避它们并不是最好的主意。
还有一种方法
由于您已经可以访问 Classic ASP,因此您始终可以构建一个为基于网络的文件提供服务的中间页面。您可以使用ADODB.Stream 对象和Response.BinaryWrite() 方法的组合来执行此操作。这样做可确保您的网络文件位置永远不会暴露给客户端,并且由于脚本的灵活性,它可用于从多个位置和多种文件类型加载资源。
这是一个基本示例(“getfile.asp”):
<%
Option Explicit
Dim s, id, bin, file, filename, mime
id = Request.QueryString("id")
'id can be anything just use it as a key to identify the
'file to return. It could be a simple Case statement like this
'or even pulled from a database.
Select Case id
Case "TESTFILE1"
'The file, mime and filename can be built-up anyway they don't
'have to be hard coded.
file = "\\server\share\Projecten\Protocollen\346\Uitvoeringsoverzicht.xls"
mime = "application/vnd.ms-excel"
'Filename you want to display when downloading the resource.
filename = "Uitvoeringsoverzicht.xls"
'Assuming other files
Case ...
End Select
If Len(file & "") > 0 Then
Set s = Server.CreateObject("ADODB.Stream")
s.Type = adTypeBinary 'adTypeBinary = 1 See "Useful Links"
Call s.Open()
Call s.LoadFromFile(file)
bin = s.Read()
'Clean-up the stream and free memory
Call s.Close()
Set s = Nothing
'Set content type header based on mime variable
Response.ContentType = mime
'Control how the content is returned using the
'Content-Disposition HTTP Header. Using "attachment" forces the resource
'to prompt the client to download while "inline" allows the resource to
'download and display in the client (useful for returning images
'as the "src" of a <img> tag).
Call Response.AddHeader("Content-Disposition", "attachment;filename=" & filename)
Call Response.BinaryWrite(bin)
Else
'Return a 404 if there's no file.
Response.Status = "404 Not Found"
End If
%>
这个例子是伪编码的,因此未经测试。
然后可以像这样在<a>中使用这个脚本来返回资源;
<a href="/getfile.asp?id=TESTFILE1">Click Here</a>
可以进一步采用这种方法并考虑 (尤其是对于较大的文件) 使用 Response.IsConnected 以检查客户端是否仍然存在并使用 s.EOS 属性以检查在读取块时流结束。您还可以添加到查询字符串参数以设置是否希望文件返回内联或提示下载。
有用的链接