浏览器的缓存有关问题

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

      存在一个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

转载于:https://www.cnblogs.com/BluceLee/p/3681341.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值