Ben*_*jer 15 html url href asp-classic
我有一个主要的脑力激荡器.
我想用经典的ASP打开一个文件.我正在使用各种变量,因为事情可能会改变,但结果是正确的.我知道这是因为我通过复制linkadress并将其放入我的URL来测试结果.现在问题是:如果我点击我的链接它没有做任何事情.不是刷新,不是重定向.没有.有谁知道我做错了什么?
好的,这是交易.我的文件并不总是本地的,这取决于我所处的环境.如果我复制粘贴我的网址的结果,它会下载.如果我点击我的网址,则不会回复.有任何想法吗?浏览器问题?(虽然我测试了5个浏览器)或其他什么?我真的被困在这里,互联网似乎不在我身边.
我有3个环境.这里的变量是这样的,以便链接起作用.我知道链接有效,因为我通过复制测试了它.是的,它确实开始,file:///是的,我确定链接是正确的.
这是我的代码行:
response.write("<td class='tab_kolom2'><a href='"&rootRs("pre_rootpad")&rootRs("rootpad_protocollen")&"\"&overzichtRs("Formuliernr")&"\Uitvoeringsoverzicht.xls' target='_blank' download>Click here</a></td>")
Run Code Online (Sandbox Code Playgroud)
编辑:链接错误/结果的屏幕截图
Lan*_*art 12
现在我们知道实际错误是什么可以形成答案.
不允许加载本地资源
是Chrome和其他现代浏览器中内置的安全例外.措辞可能不同,但在某种形式或形式上,它们都有适当的安全例外来处理这种情况.
在过去,您可以覆盖某些设置或应用某些标志,如
--disable-web-security --allow-file-access-from-files --allow-file-access
在Chrome中(请参阅/sf/answers/1541890171/)
这是有原因的
在这一点上虽然值得指出这些安全例外存在是有充分理由的,并且试图规避它们并不是最好的主意.
由于您已经可以访问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
%>
Run Code Online (Sandbox Code Playgroud)
此示例是伪编码的,因此未经测试.
然后可以<a>像这样使用此脚本来返回资源;
<a href="/getfile.asp?id=TESTFILE1">Click Here</a>
Run Code Online (Sandbox Code Playgroud)
可以进一步采用这种方法并考虑(特别是对于较大的文件)以块的形式读取文件,Response.IsConnected以检查客户端是否仍然存在以及s.EOS在读取块时检查流的末尾的属性.您还可以添加查询字符串参数以设置是否希望文件以内联方式返回或提示下载.
使用METADATA导入DLL常量 -如果你有麻烦adTypeBinary要计入初始确认,总是更好然后就硬编码1.
内容处理:"内联"和"附件"有什么区别?- 有关Content-Disposition客户端行为方式的有用信息.
对于人们不喜欢修改chrome的安全选项,我们只需python从包含本地文件的目录启动一个http服务器:
python -m SimpleHTTPServer
Run Code Online (Sandbox Code Playgroud)
对于python 3:
python3 -m http.server
Run Code Online (Sandbox Code Playgroud)
现在,您可以直接从js代码或外部访问http://127.0.0.1:8000/some_file.txt来访问任何本地文件
您将必须提供一个可通过浏览器访问的文件链接,例如:
<a href="http://my.domain.com/Projecten/Protocollen/346/Uitvoeringsoverzicht.xls">
Run Code Online (Sandbox Code Playgroud)
与
<a href="C:/Projecten/Protocollen/346/Uitvoeringsoverzicht.xls">
Run Code Online (Sandbox Code Playgroud)
如果直接将“ Projecten”文件夹公开给公众,则您只需要提供以下链接即可:
<a href="/Projecten/Protocollen/346/Uitvoeringsoverzicht.xls">
Run Code Online (Sandbox Code Playgroud)
但是请注意,您的文件随后可以被搜索引擎索引,具有此链接的任何人都可以访问,等等。