相关疑难解决方法(0)

缓存控制:无存储,必须重新验证未发送到IIS7 + ASP.NET MVC中的客户端浏览器

我试图确保某个页面永远不会被缓存,并且在用户单击后退按钮时从不显示. 这个非常高评价的答案(目前1068支票)说使用:

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
Run Code Online (Sandbox Code Playgroud)

但是在IIS7/ASP.NET MVC中,当我发送这些头时,客户端会看到这些响应头:

Cache-control: private, s-maxage=0 // that's not what I set them to
Pragma: no-cache
Expires: 0
Run Code Online (Sandbox Code Playgroud)

缓存控制头怎么了?IIS7或ASP.NET本机的内容是否会覆盖它?我检查了我的解决方案,我没有覆盖此标头的代码.

当我Response.Headers.Remove("Cache-Control");首先添加时,它没有任何区别:

Response.Headers.Remove("Cache-Control");
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
Run Code Online (Sandbox Code Playgroud)

当我添加一个[OutputCache]属性时:

[OutputCache(Location = OutputCacheLocation.None)]
public ActionResult DoSomething()
{
   Response.Headers.Remove("Cache-Control");
   Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   Response.AppendHeader("Pragma", "no-cache");
   Response.AppendHeader("Expires", "0");

   var model = DoSomething();
   return View(model);
}
Run Code Online (Sandbox Code Playgroud)

然后客户端响应标头更改为:

Cache-control: no-cache
Pragma: no-cache
Expires: 0
Run Code Online (Sandbox Code Playgroud)

哪个更接近,但仍然不是我要发送的标题.这些标题在哪里被覆盖,我该如何阻止它?

编辑:我已经检查过,错误的标题被发送到Chrome,FF,IE和Safari,所以它看起来是一个服务器问题,而不是浏览器相关的问题.

c# asp.net-mvc iis-7 cache-control http-headers

28
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

cache-control ×1

http-headers ×1

iis-7 ×1