输出缓存-基于PageLoad()中设置的值的GetVaryByCustomString [英] Output Caching - GetVaryByCustomString based on value set in PageLoad()
问题描述
我正在使用ASP.net输出缓存,并且想要实现它的GetVaryByCustomString()版本.但是,当缓存基于页面的PageLoad()中设置的值时,我遇到了一个问题.
I am using ASP.net Output Caching and want to implement GetVaryByCustomString () version of it. However I've gotten into a problem when the cache is based on a value set in the PageLoad() of a page.
加载Default.aspx时,我要显示的USER CONTROL版本基于需要通过数据库查询的URL.
When Default.aspx load, the version of the USER CONTROL I would like to show is based on the URL which needs to go through a database query.
www.website.com/apples将加载,并在页面后面的代码中,对数据库进行查询,检索所需的值.
www.website.com/apples will load and in the code behind of the page, I make a query to the database, retrieve the values I want.
是否可以使用输出缓存,或者我需要实现自己的变体.
Would it be possible to use output caching, or would I need to implement my own variation of it.
是否可以在页面生命周期中更早地查询数据库,以便在执行GetVaryByCustomString时已经设置了变量?
Would it be possible to querying the Database earlier in the page lifecycle such that when GetVaryByCustomString is executed, the variable will be already set?
推荐答案
我将分配变量的代码移到了似乎在GetVaryByCustomString()之前执行的Page_PreInit方法中.
I moved the code of assigning the variable into the Page_PreInit method which seems to be executing before the GetVaryByCustomString().
这篇关于输出缓存-基于PageLoad()中设置的值的GetVaryByCustomString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!