0

I have a simple 'file download' generic handler which sets the response contenttype and headers before sending the file through the same response.

I also have Response.Cache.SetCacheability(HttpCacheability.server) set in the global.asax.

As I have noticed from various sources, Internet Explorer doesn't like this no-cache setting and gives an error when trying to download the file (requested site unavailable or cannot be found).

I thought maybe I could override this setting in the .ashx page, so I alter the response's cacheability setting to public. This did not solve the issue... removing the line from global.asax does solve the problem but obviously affects the whole site.

Is there a way of setting the cachability just for my generic handler?

Cheers :D

Tabloo Quijico
  • 700
  • 2
  • 10
  • 26

1 Answers1

0

Can you just check whether the request is made to your generic handler and provide the appropriate cache settings depending on the result ? Something like this:

public void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
{
    if (!HttpContext.Current.Request.Url.AbsolutePath.EndsWith("MyHandler.asxh", StringComparison.InvariantCultureIgnoreCase))
    {
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);
    }
}
volpav
  • 5,090
  • 19
  • 27
  • Thanks for that, I was just wondering if I could override this value on the odd occasion that I'm requesting a specific page - therefore avoiding the URL check for every request. On a side-note, my SetCacheability code was originally in application_BeginRequest - is there a benefit to your example of placing it in OnPreRequestHandlerExecute? Thanks :) – Tabloo Quijico Feb 01 '11 at 16:39
  • I guess it doesn't matter where you put this check (BeginRequest or PreRequestHandlerExecute). This is what I have in one of my projects ;-) – volpav Feb 02 '11 at 06:38