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

q3qa4bjr  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(100)

我有一个asp.net网站,默认情况下发送以下缓存在头部:
缓存控制:私有
我想将Cache-Control更改为:

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

字符串
但是,当我将以下内容添加到Web配置时:

<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”?

4ioopgfo

4ioopgfo1#

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

字符串

fhity93d

fhity93d2#

在system.web部分中为http://www.system.web元素添加一个 sendCacheControlHeader=“false” 属性可以解决这个问题。

<system.web>
  <httpRuntime targetFramework="4.8" sendCacheControlHeader="false" />
...

字符串
https://learn.microsoft.com/en-us/dotnet/api/system.web.httpresponse.suppressdefaultcachecontrolheader?view=netframework-4.8.1

相关问题