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

  • 相关阅读:
    js中的面向对象part2
    js中值类型和引用类型的区别
    js中三大引用类型
    js中的重点
    html和css区别
    面向对象part1
    null和undefined的区别
    前端面试题js篇
    行内元素和块级元素的区别
    学习网站
  • 原文地址:https://www.cnblogs.com/BluceLee/p/3681341.html
Copyright © 2011-2022 走看看