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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With