I'm using Asp.Net Core RC2 and Kestrel as my web server. I need to ensure that requests (in this case all of them) are responded to with a no-cache header so that the browsers get the newest version (not 304).
Is there a way in Startup to configure Kestrel or a way to inject this step into the pipeline?
EDIT: no-store may be a better choice in my situation: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching "no-store Response is not allowed to be cached and must be fetched in full on every request."
no-cache. The no-cache response directive indicates that the response can be stored in caches, but the response must be validated with the origin server before each reuse, even when the cache is disconnected from the origin server.
The cache-control "no-store" option will prevent the request and response from being stored by the cache. Adding the "private" option will prevent proxies from caching the page.
To enable caching, Duration must be set to a positive value and Location must be either Any (the default) or Client . The framework sets the Cache-Control header to the location value followed by the max-age of the response.
Cache-Control: No-Store The no-store directive means browsers aren't allowed to cache a response and must pull it from the server each time it's requested. This setting is usually used for sensitive data, such as personal banking details.
You can use middleware to work with headers. For example, you can force no-cache cache-control by adding the following to the top of your Startup's Configure method:
app.Use(async (httpContext, next) =>
{
httpContext.Response.Headers[HeaderNames.CacheControl] = "no-cache";
await next();
});
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