I've been trying to fix something on a secure website (https) which is an Export to Excel button that generates a CSV file.
It works on Firefox, Chrome , etc... but not in Internet Explorer.
I have changed the headers eliminating the no-cache
and also edited the IIS http header configuration setting an expiration date of 1 day.
I have no idea of what can be going on and how to solve it.
Do you guys have any idea of how to fix this stuff ? I've read so many posts and they're all saying the same thing... caching.
Thanks,
UPDATE 1 :
regarding the error I receive, I receive an IE Alert saying "Internet explorer cannot download filename.aspx from web.address.com
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.
As I said, it all works out of SSL (https), but the export to excel button, breaks in https.
UPDATE 2:
I'm using these headers:
Response.ClearContent();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + name.Trim() + ".csv");
Response.AddHeader("Cache-Control", "no-cache");
Response.AddHeader("Pragma", "public");
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.AddHeader("Content-Length", "2026");
Response.Charset = "";
//Response.ContentType = "application/vnd.ms-excel";
Response.ContentType = "text/csv";
The issue is because, before IE9, Internet Explorer downloads do not work over SSL when using cache control headers (http://support.microsoft.com/kb/323308).
Just remove: Response.AddHeader("Cache-Control", "no-cache");
This works in https for IE 6,7 & 8.
Microsoft changed IE to not automatically convert a plain text file (e.g. CSV). You have to send the right MIME type. I don't have the info handy, though.
Having had problems with IE and ssl in the past, I've found that the following headers
Cache-Control: cache, must-revalidate
Pragma: public
Content-Type: application/vnd.ms-excel // MIME type
Content-Disposition: attachment; filename="excelDownload.xls"
Content-Transfer-Encoding: binary
Content-Length: 1024 // size as appropriate
work for me (in addition to the usual Expires and Last Modified headers)
My solution is very similar to the previous person (TGuv). I removed the following line of code it works fine:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Add the request Parameters and it will work-
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Cache-Control", "max-age=30");
response.setHeader("Pragma", "public");
response.setContentType("application/docx");
We faced this problem at work, it turned out to be a bug in Internet Explorer (in our case IE8-), that gives an error when trying to download a file in SSL . The problem is that if the server sends to the browser an http header that disables caching, Explorer gives an error.
The solution server side is that you should overwrite this header to tell IE8 to cache the response, with Cache-Control: private
for example.
Be careful that some application servers (such as in our case Websphere Application Server) append automatically no-cache="Set-Cookie"
when a cookie is set.
Finally, there is another solution, if applicable, that solves the problem, but it should be applied client-side on the browser:
look at Method 1:
http://support.microsoft.com/kb/2549423