Setting Output Cacheability Programmatically is Not Working - In Custom Handler

J

Jordan S.

Using .NET 3.5... in a "plain old" .aspx page I have the following code in
the Init event:

this.Context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
this.Context.Response.Cache.SetCacheability(HttpCacheability.Public);
this.Context.Response.Cache.SetValidUntilExpires(false);

It works great. Testing shows that the page is cached for 60 seconds as
expected. Specifically, I insert the current date/time into the Response
buffer, request the page, then hit F5 to see if the date/time value changes.
It doesn't change until after 60 seconds have passed. That's as expected.

But the exact same code seems to have no effect (the page isn't cached) when
it's located in the Init event of a custom page that is built dynamically
and entirely "from scratch" (from scratch - meaning that there is no aspx
file to speak of... just a custom http handler that extends Page). Of
possible relevance here is that my app has two http handler factories in
play - one is ASP.NET's built-in factory for aspx pages, and another http
factory that receives requests for dynamic pages. This second factory routes
requests to the custom http handler that extends Page. In Global.asax
BeginRequest, I call Context.RewritePath() to cause the requested page to be
renamed to the page type for which requests are routed to my custom factory
and subsequently built by my custom handler. So this amounts to URL
rewriting. It should be noted that there is no querystring - much less
querystring parameters that are changing between repeated requests for this
page.

So it is in this second "non standard" execution path that the output
cacheing is not working. What could be - or is likely - happening here to
prevent output caching of the dynamically constructed page?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top