使用新值替换使用 web.config 的缓存控制

Rob*_*ith 5 asp.net iis web-config asp.net-mvc-4

我有一个 asp.net 网站,默认情况下在标头中发送以下缓存:

缓存控制:私有

我想将 Cache-Control 更改为:

no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
Run Code Online (Sandbox Code Playgroud)

但是,当我将以下内容添加到网络配置时:

<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="Cache-Control" />
<remove name="Pragma" />
<remove name="Expires" />
<add name="Cache-Control" value="no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0" />
<add name="Pragma" value="no-cache" />
<add name="Expires" value="0" />
</customHeaders>
</httpProtocol>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

它仍然将 Cache-Control 标头中的“私有”字符串发送到客户端:

Cache-Control
private,no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
Run Code Online (Sandbox Code Playgroud)

您可以注意到它甚至没有在“private”后面放置空格,它仍然将其添加到响应的开头。如何使用 web.config 从 Cache-Control 中删除“私有”?先谢谢了。

sam*_*mwu 4

将以下代码添加到您的 web.config,清除 browser\xe2\x80\x99s 缓存并重试

\n
<system.webServer>\n  <httpProtocol>\n    <customHeaders>\n      <add name="Cache-Control" value="no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0" />\n    </customHeaders>\n  </httpProtocol>\n</system.webServer>\n
Run Code Online (Sandbox Code Playgroud)\n