Exclude routing parameters in VaryByParam for Asp.Net 4
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" %>开发者_StackOverflow;
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.
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}
Try this:
routes.MapPageRoute("video-browse", "video/{id}/{title}/",
"~/routeVideo.aspx?id={id}");
You may need to set validateIntegratedModeConfiguration to false in your web.config.
Eg. see...
Outputcache doesn't work with routing
精彩评论