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 =)

Tuesday, May 15, 2012

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

Recently, I faced an exception "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine." when trying to read an excel file from my .net web application. It is working fine on my development machine but after I deployed it to the production server, it hits the error. The cause of the issue is that the web server hosting my application is running in x86 version of Windows and the default compile option of my application is set to run at Any CPU (For vb.net, the compile option can be set in the Project Properties --> Compile --> Advanced Compile Options).

The solution to the problem:
1. Set the Target CPU in the compile option to x86 and rebuild.
2. In web  server IIS, set the application pool of your application to allow 32bit .net application (Select your application pool --> Advanced Settings. Under the General category, change the setting "Enable 32-Bit Application" to True).

Hope it helps =)