Set cache-control headers for static files to max one week

This commit is contained in:
Simon Martens
2024-11-28 15:41:32 +01:00
parent faadeec09d
commit 3a2557c21e

View File

@@ -68,6 +68,14 @@ if (!app.Environment.IsDevelopment()) {
} }
app.UseAuthorization(); app.UseAuthorization();
app.UseStaticFiles();
var cacheMaxAgeOneWeek = (60 * 60 * 24 * 7).ToString();
app.UseStaticFiles(new StaticFileOptions {
// Set ETag:
OnPrepareResponse = ctx => {
ctx.Context.Response.Headers.Add("Cache-Control", "public, max-age=" + cacheMaxAgeOneWeek);
},
ServeUnknownFileTypes = true,
});
app.MapControllers(); app.MapControllers();
app.Run(); app.Run();