ASP.NET:缓存设置由从主 html 文件调用的引用文件继承?

问题描述 投票:0回答:1

我的环境:

  • ASP.NET Core MVC

我将属性

[ResponseCache(NoStore = true)]
添加到控制器中 Action 方法的顶部。通过此缓存设置,html 将不会被缓存。我明白这一点。但是页面引用的 JavaScript、CSS、图像文件等资源又如何呢?页面的缓存设置会被所有从主 html 文件调用的引用文件继承吗?

html asp.net-core-mvc
1个回答
0
投票

我们可以将其设置在

UseStaticFiles
中间件中。

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        const string cacheControlValue = "no-store"; 
        ctx.Context.Response.Headers.Append("Cache-Control", cacheControlValue);
    }
});

© www.soinside.com 2019 - 2024. All rights reserved.