【问题标题】:asp.net core 2.2 response cache not work on browserasp.net core 2.2 响应缓存在浏览器上不起作用
【发布时间】:2019-01-30 00:40:14
【问题描述】:

响应缓存在 Postman 中运行良好但缓存在其他浏览器中不起作用,并且浏览器中的“Cache-Control”为“public, max-age=60”。 并且每次刷新浏览器都会调用 action 方法。 我的 API 代码:

[HttpGet]
    [ResponseCache(Duration =60)]

    public IActionResult GetAllCustomer()
        {           
        Request.HttpContext.Response.Headers.Add("X-Total-Custumer", _h_Plus_SportsContext.Customer.Count().ToString());

        return new ObjectResult(_customerService.GetAllCustomer())
        {
            StatusCode = (int)HttpStatusCode.OK
        };
    }

【问题讨论】:

  • 请检查您使用的浏览器的开发者工具栏是否没有开启禁用缓存。
  • @Jb_Dda,显示你的 Startup 类配置代码。

标签: c# asp.net-core asp.net-core-webapi asp.net-core-2.2


【解决方案1】:

您应该提供更多上下文,但 Chrome 和可能的其他浏览器默认发送值为 0 的 Cache-control 标头(即使 Chrome 开发工具未选中禁用缓存也会发生这种情况):

一种解决方法是点击指向要测试的链接的链接,或使用 here 指示的后退按钮。

【讨论】:

    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 2014-11-03
    • 2019-09-29
    • 2016-09-18
    • 2017-01-09
    • 2012-04-22
    相关资源
    最近更新 更多