Content-Length header ignored by IIS 6?

孤街醉人 提交于 2019-12-11 03:17:02

问题


I'm working on a web app that includes the ability to save uploaded files. Files are stored in a SQL database in an "image" column, and served via a GetFile.aspx page using Response.BinaryWrite().

Until yesterday I was having problems with downloading Office 2007/2010 files. The file would download without trouble, but when Word (or Excel, or whatever Office program) opened it, it would complain about a corrupt file. But it would still open without any immediately apparent problems or missing data. The solution turned out to be to include a Content-Length header in the response:

If dr.Read() Then
  Response.Clear()
  Response.Buffer = True
  Response.AppendHeader("Content-disposition", "attachment;filename=" + Server.UrlEncode(dr("FileName").ToString()))
  Response.AppendHeader("Content-Length", dr("ContentSize").ToString())
  Response.ContentType = dr("ContentType").ToString()
  Response.BinaryWrite(dr("FileContent"))
End If
dr.Close()
Response.Flush()
Response.End()

dr is a SqlDataReader.

This worked great on my local dev machine (Windows 7, IIS 7.5, ASP 2.0). Files downloaded and opened without a problem. But on our test server (Windows Server 2003, IIS 6), it's still an issue. I took a look at the traffic using WireShark, and discovered that my Content-Length header wasn't present! Everything else I am setting (including a test header: Response.AppendHeader("TestHeader", "TestValue") shows up. I made sure that ContentSize has a value in the data I'm getting, and I even tried changing it to Response.AppendHeader("Content-Length", "1234567") to just get a value in there. Nothing shows up!

I also tried Fiddler to look at the traffic; my dev machine does indeed include the content-length property (though it's apparently off by one byte...Fiddler reported a protocol violation), and the test server does not!

What's going on? Is IIS 6 ignoring the header for some reason? Is there a setting I need to change?

来源:https://stackoverflow.com/questions/5914675/content-length-header-ignored-by-iis-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!