Friday, October 30, 2009

Downloading Dynamic files in Internet Explorer with SSL

I recently had a problem while trying to download a file that was being generated dynamically from an ASP.NET application.

This was being done the following way:

Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=EXAMPLE.bin");
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.AddHeader("Content-Length", /* The length */);
Response.ContentType = "/*Wanted content type*/";
Response.OutputStream.Write(/* Your File */);
Response.Flush();
Response.End();

When you run this code this will work perfectly for Firefox and IE, allowing you to download the generated file.

However, once you enable SSL encryption on this website, you will get to following error message in Internet Explorer :

Internet Explorer cannot download <PAGENAME> from <SERVERNAME> .
Internet Explore was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later.

You can fix this problem by adding the following line above your header definitions.

Response.ClearContent();
Response.ClearHeaders();

This way the request headers will be set correctly and you will be able to download your file from your SSL encrypted website.

Opening of My Blog

Hi everyone,

My name is Maarten De Wilde, I am 21 years old. And I am currently working for RealDolmen.

I have been working with Silverlight 2 & 3 for the last year in combination with some ASP.NET development.

This blog, will present issues I have encountered during my development within these platforms as well as information regarding development in general.

I hope you will find my blog interesting to read.