如何在asp.net中强制清除缓存

编程入门 行业动态 更新时间:2024-10-26 17:21:35
本文介绍了如何在asp中强制清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在asp中强制清除缓存

How to force clear cache in asp

推荐答案

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

将此代码放入页面加载。现在缓存浏览器中没有数据会尝试从serv获取页面

Put this code in page load. Now there will be no data in cache browser will try to get the page from the serv

我试试这个但是看起来不行吗 public void DisablePageCaching() { //用于禁用页面缓存 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(); HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); } private void ClearCache() { DictionaryEntry entry = default(DictionaryEntry); foreach(System.Web.HttpContext.Current.Cache中的DictionaryEntry entry_loopVariable) { entry = entry_loopVariable; System.Web.HttpContext.Current.Cache.Remove(entry.Key.ToString()); } IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator(); while(enumerator.MoveNext()) { HttpContext.Current.Cache.Remove(enumerator.Key.ToString()); } HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Expires = 0; HttpContext .Current.Response.CacheControl =no-cache; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache); HttpContext.Current.Response。 Cache.SetNoStore(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1 ,0,0,0)); HttpContext.Current.Response.AppendHeader(Pragma,no-cac他); HttpContext.Current.Response.AppendHeader(,); HttpContext.Current.Response.AppendHeader(Cache-Control,no-cache); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,private); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,no-store); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,must-revalidate); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,max-stale = 0); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,post-check = 0); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Cache-Control,pre-check = 0); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Pragma,no-cache); // HTTP 1.1 HttpContext.Current.Response.AppendHeader(Keep-Alive,timeout = 3,max = 993); // HTTP 1.1 } i try this but it seems not working public void DisablePageCaching() { //Used for disabling page caching 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(); HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); } private void ClearCache() { DictionaryEntry entry = default(DictionaryEntry); foreach (DictionaryEntry entry_loopVariable in System.Web.HttpContext.Current.Cache) { entry = entry_loopVariable; System.Web.HttpContext.Current.Cache.Remove(entry.Key.ToString()); } IDictionaryEnumerator enumerator = HttpContext.Current.Cache.GetEnumerator(); while (enumerator.MoveNext()) { HttpContext.Current.Cache.Remove(enumerator.Key.ToString()); } HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Expires = 0; HttpContext.Current.Response.CacheControl = "no-cache"; HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache); HttpContext.Current.Response.Cache.SetNoStore(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ExpiresAbsolute =DateTime.Now.Subtract(new TimeSpan(1,0,0,0)); HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); HttpContext.Current.Response.AppendHeader("", ""); HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1 HttpContext.Current.Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1 }

如果你想设置当前页面的清除缓存,那么在按钮点击和页面加载时写下面的代码,它会工作对我来说。 HttpResponse.RemoveOutputCacheItem(/ pagecontentdetail.aspx) If you want set clear cache of current page then write below code on button click as well as on page load, It will work for me. HttpResponse.RemoveOutputCacheItem("/pagecontentdetail.aspx")

更多推荐

如何在asp.net中强制清除缓存

本文发布于:2023-11-13 21:42:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   如何在   asp   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!