Monday, August 6, 2012

Download to Excel Failed using IE with SSL

Recently, I was working with a web application that allows user to download an excel format report from the web. It works fine during the development, but when we tried to deploy our code into a server hosted with SSL certificate, the download to excel feature fails in IE (it is still working fine in FF though). After some googling, we found out that it was a common error people has been posting around the forums. This is typical issue only happen in IE.

For IE, in order to open (or download) an Office document from Internet, it has to save the file to local cache directory first before loading the document with associated application. If the file fails to store to cache directory, the operation will fail. So, how it relates to SSL? This is because, for web hosted using SSL certificate, IE enforces any no-cache request. If no-cache header presents on the web page, IE cannot cache the page and, consequently, fails to open the file.

Here is the link from Microsoft that explains the issue.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q316431

The application I was working on, is an existing application, and the download to excel page is a new page I've added to the application. I did not add the no-cache header to the page, however, the new page is inherits from an existing base page that consists of no-cache header, which explain why my new page fails.

To solve this problem, what I did is just add a line of code to remove the header when user tries to download the report. The line of code that does the magic is:

Response.ClearHeader()

The code above will clear the header added through the base page so that the download feature will work as expected in SSL environment for IE browser.

Hope this helps =)