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

  • 相关阅读:
    Freemaker Replace函数的正则表达式运用
    [Android]使用Spring for Android改善数据交互流程
    [Freemarker]自定义时间戳函数
    [jquery.validate]自定义方法实现"手机号码或者固定电话"的逻辑验证
    [Javascript]网页链接加上时间戳防止串用户
    支付系统设计
    java设计模式-抽象工厂模式
    IDEA解决maven多module出现多root的问题
    java设计模式-工厂方法模式
    java设计模式-单例模式
  • 原文地址:https://www.cnblogs.com/BluceLee/p/3681341.html
Copyright © 2011-2022 走看看