[英]Disable ASP.net Cache
Is there a way to disable asp.net caching on selected page. 有没有办法在选定的页面上禁用asp.net缓存。 It would be nice if this can be done from the web.config. 如果可以从web.config完成这将是很好的。
<!-- In the page itself -->
<%@ OutputCache Location="None" %>
Or 要么
// In the code-behind
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Unfortunately, it has to be done within the page. 不幸的是,它必须在页面内完成。 There's no easy way to do it from web.config. 从web.config做起来没有简单的方法。 For more information, check out: 有关更多信息,请查看:
Yes you can if you are willing to create your own config section: http://msdn.microsoft.com/en-us/library/2tw134k3.aspx 是的,如果您愿意创建自己的配置部分,可以: http : //msdn.microsoft.com/en-us/library/2tw134k3.aspx
In your config section put something like, 在您的配置部分中添加类似的内容,
<cachingConfig>
<path>/Navigation/Menu.aspx</path>
<path>/Target/Console.aspx</path>
<path>/Target/Charting/Chart.aspx</path>
</cachingConfig>
You could add more properties such as duration if you like. 如果您愿意,可以添加更多属性,例如持续时间。
Then, on the page_Init method of your pages, check this configuration section and call the following where appropriate: 然后,在页面的page_Init方法中,检查此配置部分并在适当的位置调用以下内容:
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Edit: Tip: Put the init code in a base class that your pages inherit, so that it is only one place. 编辑:提示:将init代码放在页面继承的基类中,以便它只是一个位置。
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.