有没有办法在选择的页面上禁用ASP.NET缓存。如果可以从web.config中完成这个操作就更好了。
<!-- In the page itself -->
<%@ OutputCache Location="None" %>
或者
// In the code-behind
Response.Cache.SetCacheability(HttpCacheability.NoCache)
不幸的是,这必须在页面内完成。从web.config中没有简单的方法来完成这个操作。了解更多信息,请查看:
如果您愿意创建自己的配置节,那么您就可以这样做: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)
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();