views:

492

answers:

2

I have inherited an old application that stores a zip file in a database and needs to retrieve this file. In Firefox is works fine, I can open the zip and each file inside it is fine. When I run it in IE7 I get the following error.

Internet Explorer cannot download ProductContentFormImage.aspx from localhost.

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

I am using the code below.

byte[] content = (byte[])Session["contentBinary"];

Response.ClearContent();
Response.ClearHeaders();
Response.Clear();

Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = "application/zip";
Response.AddHeader("Content-Length", content.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=content.zip");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(content);
Response.End();
+5  A: 

This is a weird little bug specific to IE.

Basically, the problem presents itself when you set your expiry to 0.

IE basically goes through the following process:

  1. IE determines that the file is something to be "downloaded", which causes IE to open the File Download pop-up.

  2. Once the user clicks on "Open" or "Save", IE tries to download the file, but since it's set to expire immediately, IE trips up.

Set your expiry to a small non-zero number like 1 minute and you should see the problem go away.

Ryan Brunner
A: 

I have found that setting HttpCacheability to private fixes the issue context.Response.Cache.SetCacheability(HttpCacheability.Private);

Andrew