禁用整个 ASP.NET 网站的浏览器缓存 [英] Disable browser cache for entire ASP.NET website

查看:32
本文介绍了禁用整个 ASP.NET 网站的浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来禁用整个 ASP.NET MVC 网站的浏览器缓存

I am looking for a method to disable the browser cache for an entire ASP.NET MVC Website

我找到了以下方法:

Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();

还有一个元标记方法(它对我不起作用,因为某些 MVC 操作通过 Ajax 发送部分 HTML/JSON,没有头部元标记).

And also a meta tag method (it won't work for me, since some MVC actions send partial HTML/JSON through Ajax, without a head, meta tag).

<meta http-equiv="PRAGMA" content="NO-CACHE">

但我正在寻找一种简单的方法来禁用整个网站的浏览器缓存.

But I am looking for a simple method to disable the browser cache for an entire website.

推荐答案

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

所有请求首先通过 default.aspx 路由 - 因此假设您可以在那里弹出代码.

All requests get routed through default.aspx first - so assuming you can just pop in code behind there.

这篇关于禁用整个 ASP.NET 网站的浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆