47

I have an issue with my website and IE. I have a file Document.ashx that becomes a document from my database depending on the parameter passed in the query string.

The file works if:

  • You're on my website and click a download link.
  • You access anything on my site and paste the URL into the address bar and access it.
  • You've already access the document link once before, even if it did error.

It doesn't work if:

  • You've not accessed my site with the current IE open and paste the link in the address bar. It displays the following error:

Windows Internet Explorer

Unable to download Document.ashx from MyHostName.

Unable to open this Internet site.

The requested site is either unavailable or cannot be found.

Please try again later.

Does anyone have a clue what would cause this. Naturally it works fine in Firefox.

I've gotten several people in my office to try it with IE and they all get the same issue. They all say it works in Firefox.

dfeuer
  • 48,079
  • 5
  • 63
  • 167
Smartie
  • 840
  • 1
  • 9
  • 16
  • 1
    Does the web server record any errors? Does the web server log the request? – ThatBlairGuy Aug 05 '10 at 13:58
  • If I set a break point on the Document.ashx ProcessRequest event it's being called and runs through without error. – Smartie Aug 05 '10 at 14:02
  • I'm not sure what to make of this. It sounds like something going awry on the server. The best I can suggest is to debug through the code and make sure what's being sent back to the client is what you think is being sent. – ThatBlairGuy Aug 06 '10 at 14:33
  • I've found if I don't set the context.Response.ContentType then it's working first time. Any idea why that would be? – Smartie Aug 12 '10 at 12:47
  • 1
    I've also found if I remove context.Response.Cache.SetCacheability(HttpCacheability.NoCache) and add back the contenttype it works. – Smartie Aug 12 '10 at 13:47

13 Answers13

24

Just like rymo said set Cache-Control: private, If your response header happen to have the Pragma :no-cache, you also have to change it to Pragma: token .

John Conde
  • 217,595
  • 99
  • 455
  • 496
Eileen
  • 241
  • 2
  • 2
  • I now recommend the solution outlined [here](http://stackoverflow.com/a/19145399/404960) – rymo Oct 02 '13 at 20:30
  • 1
    I have added this in my program but in my case cache controle got overide and showing no-cache no-store ? any idea how to resolve this. – Sai prateek Mar 20 '14 at 15:10
  • `Pragma: no-cache` snuck into our headers recently and broke all our downloads in IE8. Still don't know how it got there, but setting `Pragma: token` fixed it. You're a life saver! – mpen Jun 02 '14 at 23:27
  • It's so late to comment here but where are you finding documentation for "Pragma: token?" This looks to me like it might be a misread of the spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32) interpreting the symbol "token" as a literal "token." It seems that setting Pragma to ANYTHING but "no-cache" (or removing it entirely) causes the error to disappear, but at what cost in terms of caching? – Omaha Aug 01 '14 at 14:44
19

Based on the KB article David offered here (Internet Explorer file downloads over SSL do not work with the cache control headers), we changed our outgoing headers away from Cache-Control: no-cache to Cache-Control: private. This seems to have resolved the IE8 problem without affecting other browsers. Beware of using Cache-Control: no-store as well.

rymo
  • 3,285
  • 2
  • 36
  • 40
16

It turns out IE8 can be made to accept fully-disabled caching, but it is very picky about the exact order of the headers. So instead of falling back to private (which allows certain caching and might not fit with your security needs) use:

Cache-Control: no-store, no-cache, must-revalidate

When specified in that exact order - first no-store THEN no-cache - IE8 will allow the file download without error. Be sure also that the Pragma header is NOT set.

rymo
  • 3,285
  • 2
  • 36
  • 40
  • 2
    I just upvoted this, but that was only on the belief that it would work. Unfortunately in our testing it didn't, we have to go for Cache-Control: private or refactor our code. – Eirik H Nov 28 '13 at 09:50
  • We ended up with no-store and Pragma: private as described here: http://stackoverflow.com/a/17276263/543549 – Eirik H Nov 28 '13 at 10:35
  • We had to both fix the "Cache-Control" value order and remove the Pragma header. – Guillaume Polet Nov 20 '14 at 10:11
  • 1
    We ran into this issue; indeed the exact order did matter, I tested it both ways and it failed if it was out of order. – jdg Jan 22 '15 at 04:23
7

This issue occurs in IE8, and possibly earlier versions - but is resolved in IE9+. It is related downloading documents over SSL.

To resolve the issue in my application, I had to add the following two headers to the download (written in PHP):

header("Cache-Control: private");
header("Pragma: cache");
Dan
  • 2,073
  • 3
  • 22
  • 30
  • 1
    This worked for me. I tried a bunch of different headers (including "Cache-Control: no-store, no-cache, must-revalidate"), and none made any difference except for this. – Moulde May 05 '14 at 14:25
  • Me too with ie 8, same problem, same solution. Well done Dan. – Déjà vu Aug 05 '14 at 12:40
6

It sounds like I problem I came accross with IE 8 only. When I was tracking down a solution I came across 2 solutions. One of them should correct this issue.

Just to let you know it is a fix on the client machine as it is how IE coded that causes the issue.

Fixes: http://support.microsoft.com/kb/815313 http://support.microsoft.com/kb/323308

rymo
  • 3,285
  • 2
  • 36
  • 40
David
  • 69
  • 1
  • 2
3

What's all the fuss about ? The issue is due to immediate cache expiration or no-cache.

Do the following to fix the issue:

Goto server system -> Run Inetmgr -> RightClick and properties on the folder(e.g images) -> httpHeaders -> Now Either uncheck Enable content expiration, or check Expire after and give 1 min.

This is for IIS 5.

There will be similar setting for IIS 6/7.

Happy programming!!

1

I had the same problem and was frustrated by trying all above methods of correcting it. Obviously I did not want a solution done at client machine so all I did was just delete the "Pragma" parameter from the header and it started working nicely. PROBLEM SOLVED.

datta bhor
  • 11
  • 1
1

if you using asp.net. remove the code with sets cache

Comment the following

       Response.Clear();
   Response.Buffer = true;
   Response.Charset = "";
   **//Response.Cache.SetCacheability(HttpCacheability.NoCache);**
   Response.ContentType = contentType;
   Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
   Response.BinaryWrite(bytes);
   Response.Flush();
   Response.End();
Sheryar Nizar
  • 285
  • 4
  • 5
0

dynamic create Iframe ,set the src to the download page loaction , append to the body.

function downloadInIFrame(fileId) { var url = "download.aspx?fileId=" + fileId; var iframe = document.createElement("iframe"); iframe.src = url; iframe.style.display = "none"; document.body.appendChild(iframe); }

those code works well for me.

phil hong
  • 59
  • 6
0

If you do 'Save target As...' or Open in new tab, it works fine. But still giving error in IE8. I have same implementation... as creating the div (display:none) having iframe, and appending it to body and set src to frame whose content type is application/binary.

Sandip Bhoi
  • 31
  • 1
  • 3
0

We had this same issue with IE8 using an MVC controller tagged with NoCache. This sets Response.Cache.SetNoStore which breaks file downloads in IE.

To resolve - you can reset the Http Cache Policy via reflection.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
0

We had this same problem embedded in our ClickOnce deployment of www.Qiqqa.com. I suspect it has to do with the "MIME Type sniffing" that IE does when it gets an application/octet-stream - I guess to protect the user from malicious stuff.

Anyway, to solve the problem, we changed the mime type of our .deploy files to be text/plain - obviously not ideal, but at the same time, I don't know a scenario where we might have a .deploy file on our server that a user would browse to outside ClickOnce.

Problem solved.

ib.
  • 27,830
  • 11
  • 80
  • 100
Jimme
  • 11
  • 1
-3

This issue is caused by a browser setting in Internet Explorer. In Internet Explorer go to Tools > options > Advanced options. In the section marked Security, locate and clear the Do not save encrypted pages to disk.

NewUser
  • 3,729
  • 10
  • 57
  • 79
Arun
  • 1