开发者

Content-Length header ignored by IIS 6?

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 mis开发者_StackOverflow中文版sing 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜