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

5

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

Cache-Control: private

我想将Cache-Control更改为:

no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0, s-maxage=0

然而,当我在web.config中添加以下内容时:

<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头中向客户端发送“private”字符串:
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中删除“private”?谢谢。
2个回答

4
将以下代码添加到您的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>

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接