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?
You now need [OutputCache] attribute on your controller actions.
With MVC actions results are cached (variation by some parameter value is possible).
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!
来源:https://stackoverflow.com/questions/2199190/outputcache-doesnt-work-with-routing