Closed Flood closed 7 years ago
I got same issue in my ASP Net Core project. I try this:
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = context =>
{
var headers = context.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
MaxAge = TimeSpan.FromDays(5),
Private = true
};
}
});
I don't think you can have "Private = true", it must be public.
I have also tried these without luck:
context.Context.Response.Headers.Add("Cache-Control", "public, max-age=2592000")
context.Context.Response.Headers[HeaderNames.CacheControl] = new string[] { "public,max-age=2592000" };
context.Context.Response.Headers.Add("cache-control", new[] { "public,max-age=31536000" });
This one seems to work:
context.Context.Response.Headers.Append("Cache-Control", "public, max-age=2592000");
I fix it by moving UseStaticFiles above the UseIdentity.
I'm trying to add Cache-Control header to all my static files using this in my startup.cs
But the Cache-Control header is not set to either images, js or css files.
Anyone that have successfully implemented this?
I'm running an Angular 2 application on the front and using ASP.NET 5 as the 'core'. Can they interfere or something?