4

I am trying to enable output caching on all ashx files in my site. I'm trying to keep the server from generating the file on each request - NOT trying to tell the browser to cache the file.

I've distilled my ashx file down to this simple code:

public class DefaultStyles : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/css";
        StringBuilder styleSheet = new StringBuilder();
        styleSheet.AppendLine(string.Format("/* Generated: {0}, {1} */", DateTime.Now.ToShortDateString(),                                                DateTime.Now.ToLongTimeString()));
        context.Response.Write(styleSheet.ToString());
    }
}

And in my web.config file, i have this:

<system.webserver>
    <caching enabled="true">
      <profiles>
        <add extension=".ashx" policy="CacheForTimePeriod" duration="00:01:00"  />
      </profiles>
    </caching>
</system.webserver>

Still, every request i make to the ashx file generates a new version with the current date and time in it.

What am i doing wrong?

Thanks.

jaminto
  • 3,895
  • 3
  • 32
  • 36
  • 1
    What version of web server are you using? I just tested it and it works fine on IIS 7.5. Could you also show the handler config settings? – amit_g Mar 17 '11 at 00:20
  • You got it, i was testing in the VS developer web server. Once i deployed the simple example above on our IIS 7 server, it worked as expected with the code above. It should be noted that this DID NOT work on our IIS 6 server. I had not realized that this was a new feature only available in IIS 7 – jaminto Mar 17 '11 at 15:22

2 Answers2

1

Maybe this will help?

http://objectmix.com/dotnet/393333-output-caching-custom-http-handler.html

It would seem to suggest that since you're not using the normal page handler, the output caching module isn't invoked.

Simon

Simon Halsey
  • 5,459
  • 1
  • 21
  • 32
1

I was actually doing everything right, just not testing in the right environment. Once i deployed the simple example above on our IIS 7 server, it worked as expected with the code above. It should be noted that this DID NOT work on our IIS 6 server. I had not realized that this was a new feature only available in IIS 7

jaminto
  • 3,895
  • 3
  • 32
  • 36