我有一个 asp.net 网站,默认情况下在标头中发送以下缓存:
缓存控制:私有
我想将 Cache-Control 更改为:
no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
但是,当我将以下内容添加到网络配置时:
<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>
它仍然将 Cache-Control 标头中的“私有”字符串发送到客户端:
Cache-Control
private,no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0
您可以注意到它甚至没有在“private”后面放置空格,它仍然将其添加到响应的开头。如何使用 web.config 从 Cache-Control 中删除“私有”?先谢谢了。
将以下代码添加到您的 web.config,清除浏览器的缓存并重试。
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Cache-Control" value="no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0" />
</customHeaders>
</httpProtocol>
</system.webServer>
向 system.web 部分中的 httpRuntime 元素添加 sendCacheControlHeader="false" 属性为我解决了这个问题。
<system.web>
<httpRuntime targetFramework="4.8" sendCacheControlHeader="false" />
...