I am using package Microsoft.AspNet.StaticFiles
and configuring it in Startup.cs
as app.UseStaticFiles()
. How can I change the headers
Based on Josh Mouch's answer above, added code to determine if it's a pdf file
Startup.cs:
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
if(ctx.File.Name.ToLower().EndsWith(".pdf"))
{
ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=86400");
}
else
{
ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=31104000");
}
}
});