【问题标题】:web.config set headers for all html filesweb.config 为所有 html 文件设置标题
【发布时间】:2019-01-14 07:50:48
【问题描述】:

我不想为我的项目中的所有 html 文件设置缓存头。我知道如何为特定文件执行此操作:

 <location path="index.html">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
            <add name="Cache-Control" value="no-cache, no-store, must-revalidate" />
            <add name="Pragma" value="no-cache" />
            <add name="Expires" value="0" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>

但是我怎样才能像通配符一样使用它来定位所有 html 文件呢?

【问题讨论】:

    标签: iis http-headers web-config


    【解决方案1】:

    恐怕通配符不是一个选项。
    您可能需要考虑从您的 Startup.cs 进行设置:

    app.Use((context, next) =>
    {
        context.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate";
        context.Response.Headers[HeaderNames.Expires] = "0";
        context.Response.Headers[HeaderNames.Pragma] = "no-cache";
        return next();
    });
    

    这是 ASP.Net core v3 示例,有关更多详细信息和您可以想象的任何环境的示例,请参阅此金星答案:How do we control web page caching, across all browsers?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-25
      相关资源
      最近更新 更多