Software development stuff.

2012-03-30

Downloading files with Internet Explorer 8 or below, and setting the Cache Control on ASP.NET MVC 3

This one is worth posting since it took some time and lots of googling to figure out.
The web site is ASP.NET MVC3, the browser is IE8 or lower version.

When downloading a file with HTTPS we get the error:
"Internet Explorer cannot download filename from sitename. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

This is a "feature" on IE: See http://stackoverflow.com/questions/3415370/ie-unable-to-download-from-unable-to-open-this-internet-site-the-request

And the best workaround is to set the "cache-control" header to "private" for these browsers.

The next problem was that setting the cacheability on MVC3 only works if you set it to a value greater than what it is now. So if you set it to NoCache, you can not set it again to Private.
See http://weblogs.asp.net/andrewseven/archive/2005/04/06/SetCacheability.aspx

So, if your website has a generic nocache policy and you want to set a specific request to "private" you need to make sure NoCache is never being set on the same request.