ASP.NET应用程序默认情况下会向响应添加缓存控制和预处理头,但有时我们需要在自己的应用程序中进行更改或删除,这时我们可以使用以下代码:
protected void Application_BeginRequest()
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
protected void Application_BeginRequest()
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.AppendCacheExtension("no-store, must-revalidate");
}
注意:上述代码应放在 Global.asax 文件的 Application_BeginRequest 方法中。