如何修改 HttpResponse 中的 Cache-Control 设置
How to modify Cache-Control setting in HttpResponse
我的 ASPNET 零总是重新加载所有 css 和 js 文件而不是使用缓存。这就是它太慢的原因。那么如何更改这个设置值呢?
您可以将 asp-append-version="true"
添加到包含 css/js 文件的 razor 页面中的 script
或 link
标签。
Abp 确实提供了在运行时创建的动态脚本。因此,如 https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3673
中所述,您可以缓存的内容存在限制
我找到原因了,ASPNET Zero 默认禁用客户端缓存。我的解决方法就是注释掉一行代码如下
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();
}
我的 ASPNET 零总是重新加载所有 css 和 js 文件而不是使用缓存。这就是它太慢的原因。那么如何更改这个设置值呢?
您可以将 asp-append-version="true"
添加到包含 css/js 文件的 razor 页面中的 script
或 link
标签。
Abp 确实提供了在运行时创建的动态脚本。因此,如 https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3673
中所述,您可以缓存的内容存在限制我找到原因了,ASPNET Zero 默认禁用客户端缓存。我的解决方法就是注释掉一行代码如下
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();
}