Question

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. I have it mostly working, but the files don't open properly (in Firefox) because my content-type header is being ignored. On the production site (IIS6) the headers are (using 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:

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."

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. 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).

Is there some way to tell IIS7 to not overwrite my ContentType header, if that's what is happening?

Was it helpful?

Solution

You have no HttpModules modifying the Request/Response? Are the web.config files exactly the same?

Where are these extra 2K bytes coming from? What's in them?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top