views:

158

answers:

2

Hi,

I'm using routing from System.Web.Routing without MVC in a standard ASP.Net Web Application Project application. This is mostly done to get neater urls in the portal we are developing (instead of ~/default.aspx?contentid=123 we have ~/{contentsubject}. The portal is not authorized and all info is in the url so in a caching scenario we can cache complete pages.

When I tried to enable output caching I noticed that no caching was done. It seems that the outputcache page directive is completely ignored. Is this true or am I missing something? Can this be fixed?

I made a small test app (I uploaded it to http://www.4shared.com/file/196605919/31903b07/OutputCacheTest.html) that just contains a page, Webform1.aspx, that uses a master page and a user control. All three output the current date and time.

When I request http//localhost/OutputcacheTest/Webform1.aspx the 10 second caching works as expected, i.e. the shown time only updates every 10 seconds.

The app also defines a wildcard route that catches all requests and returns the same Webform1.aspx as a handler. So when requesting http//localhost/OutputcacheTest/myroute the same page is executed but now the caching doesn't work, i.e. the current time is shown on every request.

Note: When using the built-in development web server both scenarios work, only IIS seems to have this problem.

Does anyone have a a solution or work around for how to enable output caching in this scenario?

Regards,
Mathias

+1  A: 

You now need [OutputCache] attribute on your controller actions.

With MVC actions results are cached (variation by some parameter value is possible).

Developer Art
Thanks for the fast answer. The problem is that since I don't use MVC, only routing, I don't have an OutputCacheAttribute since that is in the System.Web.Mvc namespace.
Mathias
In that case I'm not sure what the right course of action would be. Maybe look in the source code of MVC to see how it is done and how to find the workaround.
Developer Art
+1  A: 

I got this working by making the module and handler registrations exactly like in this article (http://msdn.microsoft.com/en-us/magazine/dd347546.aspx).

Earlier I had my registrations last in the block and now I moved them to the top. I also added attribute runAllManagedModulesForAllRequests="true" in this block
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">

So now outputcache page directive is working!

Mathias