ASP.net不缓存具有特定查询字符串的页面
我知道我可以使用VaryByParam属性,但它所做的并不完全是我的目标 发生的情况是,根据查询字符串缓存页面的不同版本 例如,Page.aspx?ID=Tom有自己的缓存版本,ID=Arnold有另一个。现在我想做的是根本不缓存阿诺德。我只想在查询字符串为Tom时缓存页面ASP.net不缓存具有特定查询字符串的页面,asp.net,caching,query-string,Asp.net,Caching,Query String,我知道我可以使用VaryByParam属性,但它所做的并不完全是我的目标 发生的情况是,根据查询字符串缓存页面的不同版本 例如,Page.aspx?ID=Tom有自己的缓存版本,ID=Arnold有另一个。现在我想做的是根本不缓存阿诺德。我只想在查询字符串为Tom时缓存页面 有什么想法吗?尝试在应用程序类中使用VaryByCustom并重写GetVaryByCustomString方法。尝试在应用程序类中使用VaryByCustom并重写GetVaryByCustomString方法。_
有什么想法吗?尝试在应用程序类中使用VaryByCustom并重写GetVaryByCustomString方法。尝试在应用程序类中使用VaryByCustom并重写GetVaryByCustomString方法。
_
<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
公共子缓存输出(ByVal页面作为页面,ByVal分钟作为整数)
Page.Response.Cache.SetExpires(Date.Now.AddMinutes(分钟))
Page.Response.Cache.SetCacheability(HttpCacheability.Server)
Page.Response.Cache.SetValidUntilExpires(True)
端接头
这很有效。请注意,包含querystring或POST参数的页面的任何版本都不会被缓存。_
公共子缓存输出(ByVal页面作为页面,ByVal分钟作为整数)
Page.Response.Cache.SetExpires(Date.Now.AddMinutes(分钟))
Page.Response.Cache.SetCacheability(HttpCacheability.Server)
Page.Response.Cache.SetValidUntilExpires(True)
端接头
这很有效。请注意,包含querystring或POST参数的页面的任何版本都不会被缓存。对于C#
最好是乘双人间几分钟。
好办法!
谢谢 对于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);
}