I hosted a website over IIS 10 and added below section config file for cache for static contents.
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" cacheControlCustom="public" />
</staticContent>...
and below is startup.cs file section
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var options = new RewriteOptions()
.AddRedirect("rent/(.*)", "/$1")
.AddRedirect("explore/(.*)", "/$1");
app.UseRewriter(options);
app.UseMyMiddleware();
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
const int durationInSeconds = 60 * 60 * 7;
ctx.Context.Response.Headers[HeaderNames.CacheControl] =
"public,max-age=" + durationInSeconds;
}
});
}
However it's not adding cache-control in response header for any static resource like images, js, css files.
Can anyone help me out? If some specific information is needed, please let me know, i'll update in question.