ASP.NET清除页面缓存

ASP.NET清除页面缓存

    (1)   Response.Buffer = true;
            Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "No-Cache");


    (2) HTML方法
        <HEAD>
        <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
        <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
        <META HTTP-EQUIV="Expires" CONTENT="0">
        </HEAD>

    (3) 重新调用原页面的时候在给页面传一个参数:    href="****.ASPX?random()"


1。 取消缓存


(2)客户端取消

<html>
<head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
</head>

(3)服务器具端取消:

服务器端:
    Response.Buffer = true;
    Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
    Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    Response.Expires = 0;
    Response.CacheControl = "no-cache";
    Response.Cache.SetNoStore();

Global里面:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
       HttpContext.Current.Response.Cache.SetNoStore();
}
<%@ OutPutCache Location="None"%>

页面基类:
public class PageBase : Page
{
     public PageBase() {}

     protected override OnLoad( EventArgs e ) {
             Response.Cache.SetNoStore();
             base.OnLoad();
     }
}

最简单的办法 :-)
学CSDN的这个论坛,在URL后面随机的加一些没用的参数,比如:
http://xxx/xxx/xxx.jpg?p=xxx

IE是用过URL来控制缓存的,这样就解决了

(4)web.config可以设置吧?

2。

(1)客户端缓存和我们常在代码中使用的Cache对象,有什么差别,当我们仅用了客户端缓存时,他对我们在代码中使用的Cache有没有什么影响!

两个完全不同的东西,Cache对象是给你自己缓存东西用的,好处是会自动清理掉过期的东西。客户端缓存是HTTP的一个规范,用于在客户端缓存网页的,有时候我们需要客户端缓存提高浏览速度,减轻服务器负担,但有时候我们又需要在客户端禁用缓存,以避免客户端看到过期的信息

(2)当客户端浏览器被关闭时,要如何移除Cache中的值。当用户是正常注销是可以做到,但是如果用户是直接关闭浏览器要如何实现呢?

<body onbeforeunload="window.open('clear.aspx','','top=4000')">

(3)1.Page.Cache,Context.Cache,HttpRuntime.Cache是否引用同一个Cache对象.

        2.它们之间的区别是什么?

         3.它们的使用场合是什么?

它们指的同一个对象,在某个请求其间,Page.Cache和HttpContext.Current.Cache是有效的,至于这2者的区别,一般是由你调用的地方决定的,如果在Page里,那么用Page.Cache,如果在global.asax或自己的函数里,那么用后者

但如果你需要在某个事件,譬如基于Timer的处理函数里访问,因为其时没有HttpContext,那么用HttpRuntime.Cache

原文地址:https://www.cnblogs.com/johnwonder/p/1762409.html