7

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

AlignedDev
  • 8,102
  • 9
  • 56
  • 91

1 Answers1

13

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();
});
N. Taylor Mullen
  • 18,061
  • 6
  • 49
  • 72