【问题标题】:ResponseCache always set Cache-Control to no-cache, no-store in ASP.net coreResponseCache 在 ASP.net 核心中总是将 Cache-Control 设置为 no-cache, no-store
【发布时间】:2021-09-01 07:08:44
【问题描述】:

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

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

阅读Response cache not working in asp.net core projectResponseCache not working in net core 3.1 后,我无法解决这个问题

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

    public const string PageName = "Home";

    public void OnGet()
    {
    }
}

【问题讨论】:

    标签: c# asp.net-core


    【解决方案1】:

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

    ASP.net core set Cache-Control: no-cache, no-store 用于每个包含防伪字段或具有Authorize属性的页面!

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

    【讨论】:

    • 对我来说,问题在于我使用的是Html.BeginForm(),它生成了防伪功能。我切换到BeginForm 的重载,我可以在其中为antiforgery 参数指定false
    猜你喜欢
    • 2022-11-17
    • 2012-11-03
    • 2011-11-26
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 2011-01-25
    相关资源
    最近更新 更多