Home > DeveloperSection > Forums > Setting ContentType = “image/tiff” and sending an image is not working in IE
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    August-26-2014 2:36 AM

 ASP.Net
Ratings:


 1 Reply(s)
 800  View(s)
Rate this:

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

    Response.OutputStream.Flush();

    Response.End();

    return;

}

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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-26-2014 5:06 AM

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. 


Don't want to miss updates? Please click the below button!

Follow MindStick