Search code examples
.netiishttp-headerscontent-disposition

content-disposition header being sent twice....once by code the other unknown


I have an .aspx page where I'm manually setting headers to force a download of a pdf file. It works fine in IE, but in chrome and firefox 8.0, it's giving an error.

I finally tracked down the source of the problem to the content-disposition header being sent twice but I have no idea how or why it's being set the first time.

The first instance of the header is just: Content-disposition: Attachment The second is: Content-Disposition:attachment; filename=download.pdf <-- this one set by code

is IIS taking over somehow and adding this first instance of the header? If so, how can I toggle it to NOT do that?

EDIT: adding the code that sets the headers

Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
                Response.WriteFile(fname);
                Response.Flush();
                Response.End();

Solution

  • Check in IIS the HTTP Headers section for that page. Make sure it's not set there.

    IIS6: http://weblogs.asp.net/joelvarty/archive/2009/03/23/force-ie7-compatibility-mode-in-ie8-with-iis-settings.aspx

    IIS7: http://technet.microsoft.com/en-us/library/cc753133(WS.10).aspx