如何在全局的asp.net webform中禁用缓存

时间:2014-05-29 12:39:17

标签: asp.net caching

有没有办法在webforms中禁用缓存,我不能拥有代码。我有一个webconfig。那是有一种方法来禁用缓存

2 个答案:

答案 0 :(得分:3)

将其放入应用beginrequest

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

答案 1 :(得分:2)

整个项目:

Response.CacheControl = "no-cache";


Response.AddHeader("Pragma", "no-cache");


Response.Expires = -1;

或针对特定页面:

Response.Cache.SetCacheability(HttpCacheability.NoCache);