Blazor 服务器独立应用程序的 IIS 输出缓存

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

我在 IIS 10 中托管 Blazor 服务器应用程序(自包含发布/部署模式)。

我熟悉为较旧的 ASP.net 项目设置输出缓存,并且希望使用它来缓存 Blazor 项目内的静态文件(css、js、png、jpg)。

在 IIS 中设置用户模式和内核模式缓存后,我运行以下命令来确认缓存条目

netsh http show cachestate

结果:

There were no cache entries corresponding to the provided URL

我怀疑这是因为该项目是作为独立项目发布的。

我应该对 JS、CSS、JPG 等静态文件使用 ASP.NET core 的中间件输出缓存吗?

asp.net-core iis blazor blazor-server-side outputcache
1个回答
1
投票

尝试一下 wwwroot 内静态文件的缓存策略:

app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        const int durationInSeconds = 60 * 60 * 24;
        ctx.Context.Response.Headers[HeaderNames.CacheControl] = "public,max-age=" + durationInSeconds;
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.