如何在HttpResponse中修改Cache-Control设置

时间:2018-07-28 14:28:07

标签: asp.net-mvc httpresponse browser-cache aspnetboilerplate

我的ASPNET零总是重新加载所有css和js文件,而不使用缓存。这就是它太慢的原因。那么如何更改此设置值?

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以在包含CSS / JS文件的剃须刀页面的asp-append-version="true"script标签中添加link

Abp确实提供了在运行时创建的动态脚本。因此,如https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3673

所述,您可以缓存的内容受到限制。

答案 1 :(得分:1)

我已经找到原因,默认情况下ASPNET零禁用客户端缓存。我的解决方案只是注释了下面的代码行

protected override void Application_BeginRequest(object sender, EventArgs e)
{
    base.Application_BeginRequest(sender, e);
    //DisableClientCache();
}

private void DisableClientCache()
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(CacheExpireDate);
    Response.Cache.SetNoStore();
}