Advertise with us

Setting ContentType = “image/tiff” and sending an image is not working in IE

I need to send an image (as a downloadable file) from an ASP web page. It is working correctly in every browser except for IE (all versions).

Here is the server side code:

bool export = Request.QueryString["Export"] != null;

if (export)


    byte[] allBytes = File.ReadAllBytes(@"C:\MyImage.tif");

    Response.ContentType = "image/tiff";

    Response.AddHeader("content-disposition", "attachment; filename=\"MyImage.tif\"");

    Response.OutputStream.Write(allBytes, 0, allBytes.Length);





And here is the JavaScript:

$('#ExportFrame').attr('src', 'Default.aspx?Export=true'); // ExportFrame is an iframe

In IE, I keep getting an error saying "Internet Explorer cannot download Default.aspx from localhost". I thought it might be an issue with loading it in an iframe element, but redirecting to the URL is not working either. The really odd thing is that going to the URL (/Default.aspx?Export=true) does not work the first time, but works every time after that. Again, this works in every browser I've tried except IE.

Any ideas?

Last updated:8/26/2014 5:06:11 AM

1 Answers

Sumit Kesarwani
Sumit Kesarwani

Hi Mark,

The aspx page had the following code to keep the page from getting cached:

// Never cache this page
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
Removing the first 2 lines and leaving only Response.Expires = -1 resolved the issue. For some reason this was preventing the image from working properly in IE.