Output (server) caching of ashx files

I am trying to enable output caching for all ashx files on my site. I am trying to get the server to generate a file for every request - DO NOT try to tell the browser to cache the file.

I overtook my ashx file 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> 

However, 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.

+4
source share
2 answers

I really did everything right, just did not test in the right environment. As soon as I deployed the simple example above on our IIS 7 server, it worked as expected using the code above. It should be noted that this DID does NOT work on our IIS 6 server. I did not understand that this is a new feature available only in IIS 7

+1
source

Maybe this will help?

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

It would seem, suppose that since you are not using a regular page handler, the output caching module is not called.

Simon

+1
source

Source: https://habr.com/ru/post/1344018/


All Articles