为了下载PDF文件而不从服务器上打开,我使用了一个很好的脚本download.js,它在Chrome中工作得很出色。但正如作者在FF中警告的那样,它会在单独的选项卡中打开下载的PDF,导致我的SPA出现导航问题。
他在Apache上说,htaccess中的这段代码可以修复它。我的应用程序在IIS8上运行。如果可能的话,我更喜欢在应用程序web.config中处理它。我可以在我的Web.config中的system.webServer中放置什么和/或在我的IIS中管理-允许共享主机提供程序。(当然,会在下面的代码中将pdf添加到FilesMatch中。)
//Easiest way to configure headers via Apache is to set Header set Content-Disposition "attachment" for files you want to be downloaded.
//So .htaccess can look like:
<FilesMatch "\.(zip|rar)$">
Header set Content-Disposition attachment
</FilesMatch>发布于 2014-08-09 04:04:33
多亏了在serverfaut上找到的这个(之前我不知道这个网站),我能够组合出一个出站规则,相当于我上面问题中的htaccess语言。(并在此过程中学到了一些很棒的东西)我现在得到了我正在寻找的Firefox下载行为,尽管我仍然需要找出处理资源未找到错误的最佳方法-欢迎建议。
<system.webServer>
<rewrite>
<outboundRules>
<rule name="Allow pdfs to be downloaded" preCondition="Only match pdfs">
<match serverVariable="RESPONSE_Content_Disposition" pattern="(.*)" negate="false" />
<action type="Rewrite" value="attachment" replace="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="^download" />
</conditions>
</rule>
<preConditions>
<preCondition name="Only match pdfs">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^application/pdf" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>https://stackoverflow.com/questions/25210183
复制相似问题