简体   繁体   English

当我使用ASP.NET传输文件时,为什么IIS7会忽略我的内容类型标头?

[英]Why does IIS7 ignore my content-type header when I use ASP.NET to stream files?

I have a simple web site with two pages. 我有一个有两页的简单网站。 One displays a list of files, and the other streams a file when it's clicked in the list. 一个显示文件列表,另一个文件在列表中单击时流式传输。 All was fine in production for 6 months, but now I have to move the site to Windows 2008/IIS7. 生产6个月都很好,但现在我必须将网站移动到Windows 2008 / IIS7。 I have it mostly working, but the files don't open properly (in Firefox) because my content-type header is being ignored. 我有它主要工作,但文件无法正常打开(在Firefox中)因为我的内容类型标题被忽略。 On the production site (IIS6) the headers are (using Fiddler): 在生产站点(IIS6)上,标题是(使用Fiddler):

HTTP/1.1 200 OK
Date: Tue, 09 Feb 2010 16:00:51 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment; filename="myfile__foo.pdf"
Content-Length: 236841
Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: -1
Content-Type: application/octet-stream

but on the test IIS7 server I get: 但在测试IIS7服务器上我得到:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 236841
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment; filename="myfile__foo.pdf"

Fiddler also reports a protocol violation and says "Content-length mismatch: Response Header claimed 236841 bytes, but server sent 238378 bytes." Fiddler还报告违反协议并说“内容长度不匹配:响应标头声称236841字节,但服务器发送了238378字节。”

My code looks like this: 我的代码看起来像这样:

            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=\"" + doc.DisplayFilename + "." + doc.FileExtension + "\"");
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.TransmitFile(file.FullName);
            Response.End();

I've been trying to fix this for a couple of days. 我一直试图解决这个问题几天。 I'm not that familiar with IIS7 and have struggled to find where to change various settings. 我对IIS7并不熟悉,并且很难找到改变各种设置的位置。 I did manage to figure out about the two Managed Pipeline Modes and fixed some other issues by switching to Classic .NET AppPool (Integrated was throwing all sorts of errors when transmitting the file). 我确实设法弄清了两种管理流水线模式,并通过切换到Classic .NET AppPool修复了一些其他问题(Integrated在传输文件时抛出了各种错误)。

Is there some way to tell IIS7 to not overwrite my ContentType header, if that's what is happening? 有没有办法告诉IIS7不要覆盖我的ContentType标头,如果这是发生了什么?

You have no HttpModules modifying the Request/Response? 您没有HttpModules修改请求/响应? Are the web.config files exactly the same? web.config文件是否完全相同?

Where are these extra 2K bytes coming from? 这些额外的2K字节来自哪里? What's in them? 它们里面有什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM