Export to Excel/CSV doesnt work on IE under SSL (https)

Challenge:

We’ve one functionality where user can save CSV/Excel file. Which was working fine in all browsers when we check it via HTTP. But it doesn’t work under IE when we do it via HTTPS.

Solution:

Cause:
1. If your page is passing caching header – Response.AddHeader(“Cache-Control”, “no-cache”);
2. And having export to CSV/Excel — Via Response.Write code.
Then it will not work in IE6/7/8 — This KB article says that this issue is fixed in IE9 — http://support.microsoft.com/kb/323308
OR remove no-cache control header from your page. But it is also required to have it as you might not want to save sensitive pages on client side. And if you remove no-cache header then it will save sensitive pages on client side. Isn’t it a real fix? Don’t worry we have a solution for you!
We googled it and found following link:
http://aspnettechstuffs.blogspot.in/2010/05/export-to-excel-does-not-work-in-ssl.html
Which worked for us in IIS 6.0 But not in IIS 7.5. Also, we wanted to avoid IIS specific changes and wanted to fix it from code. So, it doesn’t affect full functionality and only affects related modules.
We added following line in top of our export to CSV/excel method:
Response.ClearHeaders();
// Following by Export to Excel and Response attribute’s logic
And it did a trick!
Happy Coding! 🙂

Good to read:

http://stackoverflow.com/questions/4672073/export-to-excel-doesnt-work-on-ie-under-ssl-https