简体   繁体   中英

Output caching a page except a user control in it

I have a page which contains a user control. The structure of the page is as shown below:

在此处输入图片说明

Incase your not able to see the above image, please check it at http://i54.tinypic.com/2r4id5f.jpg Now, apart from the contents of the UserControl, I'd like to cache the entire page. I tried using the OutputCache attribute in the .aspx page, however it caches the contents of the UserControl as well.

Kindly let me know how will I be able to cache the contents of the page except that of the user control.

Thanks in advance.

Look at using substitutions.

This should help

However, the snag is, since substitution is done outside of the Page lifecycle, you can't render a user control for your substitution. You have to write a method that returns a string for the substitution. But this may work for you.

I think you can use the asp.net Substitution control to achieve this. Here is a link to ScottGu walking through an example .

The basic idea is that you cache you whole page as per usual, but mark parts for substitution that can be replaced for each request.

I think you are looking for VaryByControl . Also check out this post on fragment caching

Have you tried adding the @OutputCache to both the usercontrol and the page but the usercontrol set the varyByParam="qsvalue;postvalue" where qsvalue is a generated query string you make random for every call of the page and postvalue is the same for postback.

The user control will still get cached, but in theory it should never get a chache hit as the qsvalue/postvalue is always different from that cached. It may not scale well - best set duration to the minimum as well, to prevent large numbers of them building up in the cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM