使用Firefox / Chrome从服务器上下载PDF文件

我有一个运行多个网站的Windows 2008 R2(虚拟)服务器。 我的客户已经通过FTP上传了几个PDF文件到一个下载目录,从那里他们可以通过网页检索。

这在IE和Safari中运行正常,但是当试图用Firefox或Chrome下载时,两个浏览器都会挂起,Firefox的post在页面底部的状态栏中停止。 我们已经在不同地点的几台电脑上试了这个,所以我认为这可能是一个服务器问题 – 尽pipe用于生成PDF的软件可能产生了与stream向Firefox / Chrome不兼容的东西。

为什么有理由可以产生这种行为? 有一些configuration设置,我需要改变?

编辑:检查标题与萤火虫 – 一个GET与206部分内容坚持

Content-Type application/pdf Last-Modified Sun, 21 Mar 2010 19:50:49 GMT Accept-Ranges bytes Etag "42da4bce2fc9ca1:0" Server Microsoft-IIS/7.5 X-Powered-By ASP.NET Date Thu, 27 May 2010 15:39:34 GMT Content-Length 329532 Content-Range bytes 27484-357015/357016 Request Headersview source Host www.caepost.co.uk User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language en-gb,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 115 Connection keep-alive Range bytes=27484-357015,27484-27485 

IIS版本7.5改变了它响应字节范围请求的方式,例如由Acrobat插件制作的请求。 如果请求是针对单个连续范围的,则IIS现在会响应“Content-Range”标题,而不是“ContentType:multipart / byteranges”标题,这实际上是有效的HTTP,但会混淆Acrobat插件。

Adobe目前正在修复: http : //kb2.adobe.com/cps/807/cpsid_80780.html

与此同时,微软提供了一个修补程序,使IIS 7.5可以回到旧的行为: http : //support.microsoft.com/kb/979543

我们升级服务器和IIS 7.5给了我们这个相同的问题。 检查标题并确认问题。

应用修补程序http://support.microsoft.com/kb/979543,但没有解决问题。 我认为这里的区别是我们的网站运行在经典模式。 (必须安装另一个产品(Imis))。 所以看来,只有当您的站点在集成模式下运行时,修补程序才能正常工作。

最后,我不得不写一个处理程序来捕获PDF文档请求,并更改响应头。

 context.Response.ContentType = "application/pdf"; context.Response.TransmitFile(filePath); context.Response.End(); 

那就是诀窍。

系统不仅限于Acrobat打开文件。 在我们的情况下,谷歌浏览器也挂了,当它试图打开PDF,无论你有什么PDF阅读器。

你能发布正在发送的响应头文件吗?

Firebugnetworking面板:
替代文字

标题查看:
替代文字

这可能是由于IIS 7.0中的压缩设置。

请求头包含以下内容:

 Accept-Encoding: gzip,deflate 

表明浏览器接受压缩的内容。

当你使用:

 context.Response.TransmitFile(filePath); 

IIS查看所设置的内容types,并决定是否压缩响应。

不幸的是,IIS似乎没有添加

 Content-Encoding: gzip 

到响应头,这意味着Firefox和Chrome无法确定数据是否被压缩。

禁用IIS中的内容压缩应该解决这个问题,但会影响整个网站。 此外,设置内容types的build议可能在某些情况下起作用。 IIS 7决定是否压缩基于MIMEtypes的响应。

http://www.iis.net/configreference/system.webserver/httpcompression提供了下面的例子来configurationApplicationHost.config文件中的httpCompression:

 <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/javascript" enabled="true" /> <add mimeType="*/*" enabled="false" /> </staticTypes> </httpCompression> 

另一个select是确保'Content-Encoding:gzip'总是被添加到Response头部,但是你需要小心确保响应真的会被压缩,这可能不是所有的内容types。