我知道我可以使用VaryByParam属性,但它所做的并不完全是我的目标。ASP.net不使用特定的查询字符串缓存页面
发生什么事是基于查询字符串缓存不同版本的页面。
例如Page.aspx?ID = Tom有它自己的缓存版本和ID = Arnold有另一个。现在我想要做的不是缓存阿诺德。我只想在查询字符串是Tom时缓存页面。
任何想法?
我知道我可以使用VaryByParam属性,但它所做的并不完全是我的目标。ASP.net不使用特定的查询字符串缓存页面
发生什么事是基于查询字符串缓存不同版本的页面。
例如Page.aspx?ID = Tom有它自己的缓存版本和ID = Arnold有另一个。现在我想要做的不是缓存阿诺德。我只想在查询字符串是Tom时缓存页面。
任何想法?
<Extension()> _
Public Sub CacheOutput(ByVal Page As Page, ByVal Minutes As Integer)
Page.Response.Cache.SetExpires(Date.Now.AddMinutes(Minutes))
Page.Response.Cache.SetCacheability(HttpCacheability.Server)
Page.Response.Cache.SetValidUntilExpires(True)
End Sub
This works。请注意,任何具有查询字符串或POST参数的页面版本都不会被缓存。
尝试使用VaryByCustom并覆盖Application类中的GetVaryByCustomString方法。
对于C#
public static void cacheOutput(Page page, double minutes)
{
page.Response.Cache.SetExpires(DateTime.Now.AddMinutes(minutes));
page.Response.Cache.SetCacheability(HttpCacheability.Server);
page.Response.Cache.SetValidUntilExpires(true);
}
这是更好地采取双重几分钟。 好的解决方案! Thx!