views:

271

answers:

3

I have a routing setting in my global.asax file:

routes.MapPageRoute("video-browse", "video/{id}/{title}/", "~/routeVideo.aspx");

My routeVideo.aspx page has caching setting:

<%@ OutputCache Duration="10" Location="ServerAndClient" VaryByParam="id" %>

But when I request http://localhost/video/6/example1 and http://localhost/video/6/example2 after this, the page is created again. So I think VaryByParam works for * but I only want compile when id changes. Is there a way to define routing parameters at VaryByParam?

I want this because title parameter is not important to me. It is there only for search engines and it is not used in my code.

+2  A: 

VaryByParam treats parameter following the question mark '?', but you routing hides this into the path. That is why caching always "see" different urls. To fix it change

"video/{title}?id={id}
Dewfy
@Dewfy But I want the url like localhost/video/someID/any-title. Also I'm getting routing parameters in this way: Page.RouteData.Values["id"]
HasanGursoy
@HasanGursoy then instead of VaryByParam use VaryByCustom. Last one gives you possibility to write own method to form key of cache system.
Dewfy
A: 

Try this:

routes.MapPageRoute("video-browse", "video/{id}/{title}/", 
                    "~/routeVideo.aspx?id={id}"); 
Raj Kaimal
@Raj Kaimal: I'm getting error "The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.Parameter name: routeUrl" when try to use "~/routeVideo.aspx?id={id}"
HasanGursoy
How about specifying the path you want? routes.MapPageRoute("video-browse", "video/{id}/{title}/", "MyFolder/MyVideos/routeVideo.aspx?id={id}");
Raj Kaimal
A: 

You may need to set validateIntegratedModeConfiguration to false in your web.config.

Eg. see...

http://stackoverflow.com/questions/2199190/outputcache-doesnt-work-with-routing/2200006#2200006

kervin
@kervin: My current configuration is caching pages with routing. validateIntegratedModeConfiguration="false" didn't help. I want just to cache my pages depending on id parameter. I want to ignore title parameter. But I can't get VaryByParam="id" working.
HasanGursoy