I’ve got this bit of code:
Response.AddHeader("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
Response.AppendHeader("Content-disposition", "attachment; filename=Bio.docx");
Response.BinaryWrite(lawyerBio.MakeDoc());
It works just fine in all major browsers, but is failing in IE8.
What IE8 is doing is the first time I hit the page, it gives a popup error that says:
Internet Explorer cannot download ‘John-Smith’ from ‘site domain’.
Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please try
again later.
If I hit OK, and then refresh the page, it downloads the file just fine, with the filename Bio.docx. It fails the first time, everytime and it works the second time, every time. John-Smith is the filename of the page this is taking place on, so it appears as if the first time through, it’s not picking up on the content-disposition.
Are there any known issues with IE8, or anything you guys can see that I’m doing wrong?
Cheers
Update
Below are the headers sent with this file:
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: no-cache, no-store
[2] => Pragma: no-cache
[3] => Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
[4] => Expires: -1
[5] => Server: Microsoft-IIS/7.5
[6] => Set-Cookie: website#sc_wede=1; path=/
[7] => Set-Cookie: website#lang=en; path=/
[8] => Set-Cookie: ASP.NET_SessionId=zabhwz55brq0ebfyjqn1c3bm; path=/; HttpOnly
[9] => Content-Disposition: attachment; filename=Bio.docx
[10] => X-AspNet-Version: 2.0.50727
[11] => Set-Cookie: SC_ANALYTICS_GLOBAL_COOKIE=323F079A90B545F39F8A6A9EB9B919DB; expires=Fri, 26-Oct-2012 17:44:57 GMT; path=/
[12] => Set-Cookie: SC_ANALYTICS_SESSION_COOKIE=118B88825A054BA1BAF327B0561C3EBB,1; path=/
[13] => X-Powered-By: ASP.NET
[14] => Date: Thu, 27 Oct 2011 17:44:57 GMT
[15] => Connection: close
[16] => Content-Length: 169581
)
I think the issue is the Cache-Control headers. See MSKB #323308. Despite its title, I have found a number of posts online that suggest that not caching downloading files might cause non-SSL websites to fail in Internet Explorer as well. I would try adding the registry value
BypassHTTPNoCacheCheckthat the KB article suggests – if it works then, you will need to remove the caching headers from your response.