这通常是由于 Blazor 服务器或浏览器缓存的问题导致的。可以通过添加以下标头来解决该问题:
在.cshtml 文件中:
在 Startup.cs 文件中:
app.UseResponseCaching();
app.Use(async (context, next) =>
{
context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
Public = true,
MaxAge = TimeSpan.FromSeconds(0)
};
context.Response.Headers[HeaderNames.Vary] = new string[] { "Accept-Encoding" };
await next();
});
这将防止浏览器或服务器缓存 CSS 文件,并在每次请求时重新加载它。