【发布时间】:2010-07-22 16:02:51
【问题描述】:
这是一个非常奇怪的问题 - 任何想法/帮助/提示将不胜感激。
我们的网络应用使用以下代码将 PDF 文件流式传输到浏览器
byte [] fileBytes = GetTheFileBytes();
string contentType = "application/pdf";
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ContentType = contentType;
context.Response.AddHeader("Content-Length", fileBytes.Length.ToString());
context.Response.AddHeader("Content-Type", contentType);
MemoryStream outputStream = new MemoryStream(fileBytes);
outputStream.WriteTo(context.Response.OutputStream);
context.Response.Flush();
这在 IIS 6 和 IIS 7 中看起来很无害并且工作正常:如果用户安装了 PDF 插件(adobe 或 foxit 等),那么 PDF 会显示在他们的浏览器中。
但是,在 IIS 7.5(Windows 7 和 Win 2008 R2)中,Foxit 插件在 IE 中挂起,而 Adobe 插件在 IE 和 FF 中挂起。即如果我输入
http://iis70Host/application/getPDF.aspx 一切都很好,但是
http://iis75Host/application/getPDF.aspx 在同一浏览器中挂起。
我正在为完全相同的浏览器提供完全相同的 PDF 文件,并且两个 Web 服务器都在 2.0 框架中运行该应用程序。
当它们崩溃时,我还没有设法从任何一个插件中获得有用的错误消息。
我认为 IIS 7.5 以某种方式损坏了文件(因为客户端浏览器和插件是相同的) - 但我发现很难想象 Web 服务器如何出错(它只是将二进制流式传输到毕竟是客户)。
- 谁能想到为什么 IIS 7.0 和 7.5 的行为会有所不同?
- 有谁知道如何从 Adobe 或 foxit 插件中获取更多调试信息? (如果我能得到它们崩溃的原因,那么也许它会给我一个关于服务器出了什么问题的线索)。
- 还有其他诊断问题的技巧吗?
跟进
我已使用 wget 捕获文件,它们完全相同。
我使用 fiddler 查看了请求和响应标头,但它们没有明确提及响应标头中的“范围”(或请求标头中的接受范围),这说明了这种可能性是 mwalker 建议的多部分请求问题。
我还是继续安装了 MS 修补程序,但这并没有帮助解决问题(因此 我更确定这不是“多部分问题”)。
所以我想我又回来乞求更多关于可能出了什么问题的想法!
以下是 fiddler 在访问运行 IIS 7.5、7.0 和 6 的主机时记录的请求和响应标头
IIS 7.5
GET /eco/dataFile.aspx?data=147098&record=9754 HTTP/1.1
Host: chrisf
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7
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
Referer: http://chrisf/eco/embeddedMedia.aspx?record=9754&search=true
Cookie: CC=test;
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 114340
Content-Type: application/pdf
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
Persistent-Auth: true
X-UA-Compatible: IE=8
Date: Mon, 26 Jul 2010 12:47:46 GMT
IIS 7.0
GET /eco/dataFile.aspx?data=147098&record=9754 HTTP/1.1
Host: chris1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7
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
Referer: http://chrisf/eco/Test1.htm
Cookie: CC=test;
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 114340
Content-Type: application/pdf
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-UA-Compatible: IE=8
Date: Mon, 26 Jul 2010 12:17:15 GMT
IIS 6
GET /mi/dataFile.aspx?data=147098&record=9754 HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*
Referer: http://mi-dev/mi/embeddedMedia.aspx?record=9754&search=true
Accept-Language: en-GB
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: mi-dev
Connection: Keep-Alive
Cookie: CC=test;
Authorization: Negotiate YII...
HTTP/1.1 200 OK
Date: Mon, 26 Jul 2010 10:37:47 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
WWW-Authenticate: Negotiate oYGg...
X-AspNet-Version: 2.0.50727
Content-Length: 114340
Cache-Control: private
Content-Type: application/pdf
【问题讨论】:
-
使用命令行下载器从网络服务器获取文件并进行比较。 wget 是我的最爱。可在此处获取:unxutils.sourceforge.net。使用 firebug 查看正在发送的标头并进行比较。答案必须是这两个不同之一。让我们知道您发现了什么。
-
保存响应流而不是直接在浏览器中查看会发生什么?您是否获得了有效的 PDF 文件?您是否使用过数据包嗅探器(或类似工具)来比较您从两个不同服务器获得的标头和响应?
-
为什么要设置两次内容类型? context.Response.ContentType = contentType;应该够了。
-
IIS 7.5 响应具有“Persistent-auth: true”标头。 Adobe 插件会不会被搞砸?您是否启用了匿名访问?