c# - ResponseCache 始终将 Cache-Control 设置为 no-cache, no-store in ASP.net core

标签 c# asp.net-core

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

但是设置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()
    {
    }
}

CacheControl

最佳答案

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

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

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

关于c# - ResponseCache 始终将 Cache-Control 设置为 no-cache, no-store in ASP.net core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69009216/

相关文章:

c# - 使用 C# 和 Xamarin 防止按 F8(播放)按钮后启动 iTunes/Music.app

c# - NAT、wcf、双工通信……需要一些见识

asp.net - 更新到 ASP.NET Core 2.0 - 软件包与 netcoreapp2.0 不兼容

git - 我的 Azure 更改未发布到我的网站上

asp.net-core - 如何在 ASP.NET CORE 3.1 中获取客户端 IP 地址?

c# - 如何在同一个 .net MVC 项目中加载单独的 JS 和 CSS 包?

c# - 如何在单个原子操作中移动 C# .NET 中的目录

c# - 使用 jquery POST 数据的启用 Ajax 的 wcf 服务在短时间内未发送

entity-framework - 获取 Entity Framework 中两个日期之间的天数

visual-studio-2013 - Visual Studio 2013 中的 ASP.NET-5