zoukankan      html  css  js  c++  java
  • 浏览器的缓存有关问题

    浏览器的缓存问题
        
        我在开发中遇到了这么一个问题:

          存在一个web页面,在这个页面内有一个信息列表,用户可以删除某个信息。

          当用户删除a信息的时候,采用的是异步请求,即:使用ajax技术向后台发送删除信息,后台删除成功,前台使用js删除a信息的html内 容,完成删除功能。这时,用户点击页面内某个链接,去了其它页面,当用户按浏览器的后退按钮,再返回到信息也的时候,显然,浏览器提取的是缓存的html 页面,显示a信息还未删除。
          
          请教各位,这个问题怎么解决?谢谢!
    ------解决方案--------------------
    我写了一个NoCache的Attribute,你可以复制一下拿去用:

        public class NoCacheAttribute : ActionFilterAttribute
        {
            public override void OnResultExecuting(ResultExecutingContext filterContext)
            {
                filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
                filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
                filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
                filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                filterContext.HttpContext.Response.Cache.SetNoStore();
                base.OnResultExecuting(filterContext);
            }
        }

    用法:

    [NoCache]
    public ActionResult Index(){
    ....
    return View();
    }
    ------解决方案--------------------
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>


        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = 0;
            Response.CacheControl = "no-cache";

    转自:http://www.myexception.cn/asp-dotnet/1597488.html

  • 相关阅读:
    迷宫最短路径问题的dfs,bfs实现
    高效率的排序算法2--归并排序
    高效率的排序算法1--快速排序
    POJ No.2386 Lake Counting
    部分和问题 --dfs
    dfs的一个小实现(啊哈算法的例题)
    HDU 5710 Digit Sum
    【视频播放器】在macOS上使用IINA
    视音频格式基础知识&视频压缩
    影视作品(电影,电视剧,PV,MAD,AMV)的制作程序
  • 原文地址:https://www.cnblogs.com/BluceLee/p/3681341.html
Copyright © 2011-2022 走看看