禁用ASP.net缓存

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

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

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

 /Navigation/Menu.aspx /Target/Console.aspx /Target/Charting/Chart.aspx  

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

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

 Response.Cache.SetCacheability(HttpCacheability.NoCache) 

编辑:提示:将init代码放在页面inheritance的基类中,这样它就只有一个位置。

  <%@ OutputCache Location="None" %> 

要么

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

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

MSDN – 设置页面的可缓存性

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