ASP.NET - 服务器控制输出缓存

是否可以从代码隐藏更改输出缓存及其特定控制的持续时间?

我的意思是,假设我有控制 News.ascx 有:

<%@ OutputCache Duration="60" VaryByCustom="language" %>

现在我想在某个地方写一些代码,它将动态决定是否使用输出缓存以及该缓存的持续时间。可能吗?

我想,我将能够使用在 CodeProject 上描述的自定义 OutputCacheProvider , 但我找不到方法。

最佳答案

您可以在此处查看详细信息 http://support.microsoft.com/kb/323290

使用response.cache作为

if (x==y) 
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);   
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(6700)); 
HttpContext.Current.Response.Cache.SetValidUntilExpires(true); 
}

见类似问题Conditionally add OutputCache Directive

https://stackoverflow.com/questions/16771611/

相关文章:

ruby-on-rails - 呈现带有错误和文件输入的表单

php - Chrome不会删除cookie?

session - 如何禁止 Symfony 将 _sess 文件写入我的/tmp 目录

gcc - 如何将源代码目录添加到 gcc 的搜索路径?

jsf - Primefaces 内联编辑数据表不起作用

css - :active css class not working correctly to m

ruby-on-rails - 从复杂的 Rails 查询导出到 CSV

ms-access - Access VBA 代码以打印每条记录的单个 PDF - 在第 10 条记

math - 双轮廓 - 噪声函数的法向量

google-maps - 使用 Google Maps Static API 验证地址