ResponseCache 在 ASP.net core 中始终将 Cache-Control 设置为 no-cache、no-store

Meh*_*hdi 4 c# asp.net-core

我想在客户端浏览器中缓存主页

但设置ResponseCache属性后,响应头设置为Cache-Control: no-cache, no-store

阅读Response cache not working in asp.net core projectResponseCache notworking in net core 3.1后,我无法修复此问题

[ResponseCache(Duration = 300)]
public class HomeModel : PageModel
{

    public const string PageName = "Home";

    public void OnGet()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

缓存控制

Meh*_*hdi 9

因为我在 _layout.cshtml 中为搜索字段添加了一个表单,其中会自动生成防伪令牌!

ASP.net core设置Cache-Control:对每个包含防伪字段或具有Authorize属性的页面不缓存、不存储!

通过从 _layout.cshtml 中移动此表单,问题得到解决!