Note that you're still free to add <meta
> tags in your HTML pages for each page you don't want to cache:
<meta http-equiv="cache-control" content="no-cache" />
Also note that if you're deploying to IIS then you still have a wwwroot
(or what you specified in project.json
) where you can put a web.config
files (parsed by IIS).
If you want to do it with configuration then add a Configure()
method in your Startup
class:
public void Configure(IApplicationBuilder application)
{
application.Use(async (context, next) =>
{
context.Response.Headers.Append("Cache-Control", "no-cache");
await next();
});
// ...
}
Note that if you want to apply that HTTP header only to certain pages you just need to check PathString
property of HttpRequest
(Request
property of HttpContext
) or if you need it for every static file (same as above if you want to apply to only some of them) using:
application.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
context.Response.Headers.Append("Cache-Control", "no-cache");
}
};
Which headers you should send to be compatible with browsers you need to support has been discussed on Making sure a web page is not cached, across all browsers.