views:

30

answers:

2

I have a very interesting issue with only specific IE implementations. I have an ASPX page that is used to write files down to the user, as part of the process the page uses the following code to write the file to the user.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=download" + System.IO.Path.GetExtension(oInfo.SupportingFilePath));
Response.ContentType = "application/octet-stream";
Response.WriteFile(Server.MapPath(oInfo.SupportingFilePath));
Response.End();

In 99.5% of the cases this works just fine, however, in certain rare circumstances within IE only on specific machines, the user is prompted to download the .aspx page, and/or is given an error message.

Anyone have an idea of what is going on here?

+1  A: 

Per RFC2231, MIME headers' parameter values have to be included in double quotes: http://www.ietf.org/rfc/rfc2231.txt (page 3, if you are interested). It should be something like "attachment;filename=""download" + System.IO.Path.GetExtension(oInfo.SupportingFilePath) + """");

LymanZerga
Wow, if this is the case, thanks....I'll have to try this.
Mitchel Sellers
THanks, this was it!
Mitchel Sellers
A: 

Although this should not be happening because you've set the ContentType and content-disposition, I believe that IE's built-in MIME sniffing/handling is what is causing the problem here. Here are a couple of work-around/hacks you can try:

  • Add the file extension to the query string on the .aspx page that is transferring the file, i.e., http://blahblahblah/page.aspx?.ext
  • If you are using IE 8, you can specify another response header for "nosniff," as specified here.

I'm still having issues with this, as documented here, but I hope one of these helps.

AJ