繁体   English   中英

禁用ASP.net缓存

[英]Disable ASP.net Cache

有没有办法在选定的页面上禁用asp.net缓存。 如果可以从web.config完成这将是很好的。

<!-- In the page itself -->
<%@ OutputCache Location="None" %>

要么

// In the code-behind
Response.Cache.SetCacheability(HttpCacheability.NoCache)

不幸的是,它必须在页面内完成。 从web.config做起来没有简单的方法。 有关更多信息,请查看:

MSDN - 设置页面的可缓存性

是的,如果您愿意创建自己的配置部分,可以: http//msdn.microsoft.com/en-us/library/2tw134k3.aspx

在您的配置部分中添加类似的内容,

<cachingConfig>
    <path>/Navigation/Menu.aspx</path>
    <path>/Target/Console.aspx</path>
    <path>/Target/Charting/Chart.aspx</path>
</cachingConfig>

如果您愿意,可以添加更多属性,例如持续时间。

然后,在页面的page_Init方法中,检查此配置部分并在适当的位置调用以下内容:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

编辑:提示:将init代码放在页面继承的基类中,以便它只是一个位置。

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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