如何在ASP.NET Core中启用ClientCache

Mar*_*arn 7 asp.net-mvc web-config clientcache asp.net-core

在ASP.net 4.5中,我们曾经能够通过在web.config中添加"ClientCache"来启用静态资源上的expires头(反过来,启用浏览器缓存),例如:

<staticcontent>
  <clientcache cachecontrolmode="UseMaxAge" cachecontrolmaxage="365.00:00:00" />
</staticcontent>
Run Code Online (Sandbox Code Playgroud)

http://madskristensen.net/post/cache-busting-in-aspnet中所述

当我们没有web.config和Startup.cs时,我们现在如何在ASP.net 5中执行此操作?

Tho*_*old 12

在Startup.cs> Configure(IApplicationBuilder applicationBuilder,.....)

applicationBuilder.UseStaticFiles(new StaticFileOptions
{
     OnPrepareResponse = context => 
     context.Context.Response.Headers.Add("Cache-Control", "public, max-age=2592000")
});
Run Code Online (Sandbox Code Playgroud)