3

I want to set no cache headers for all html files in my project. I know how to do it for a specific file:

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

But how can I use it like a wildcard to target all html files?

Chris
  • 13,100
  • 23
  • 79
  • 162

1 Answers1

0

Wildcard is not an option I'm afraid.
You may want to consider setting this from your Startup.cs instead:

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();
});

This is the ASP.Net core v3 example, see this gold star answer for more details and examples for any environment you can imagine: How do we control web page caching, across all browsers?

Søren Ullidtz
  • 1,504
  • 1
  • 15
  • 26