如何在ASP.NET中为错误页面指定最大使用期限

问题描述 投票:0回答:1

当我的ASP.NET服务器(在IIS上运行)上发生错误时,该服务器当前提供一个静态页面。这是在我的web.config的httpErrors元素中配置的,如下所示:

<httpErrors errorMode="Custom" existingResponse="Replace">
  <error statusCode="404" path="404.htm" responseMode="File" />
  <error statusCode="500" path="500.htm" responseMode="File" />
</httpErrors>

检查服务器的响应时,看到一个cache-control: private响应头。很好,尽管我想控制此页面的缓存时间。如何将max-age=x添加到此cache-control标头?

asp.net-mvc iis cache-control iis-10
1个回答
0
投票

我尝试了很多方法,并且只有当我为404错误设置自定义错误页面时,它才似乎起作用。

<system.webServer>
  <httpProtocol>
        <customHeaders>
            <add name="Cache-Control" value="max-age:12300" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.