【问题标题】:How to send Cache-Control: no-cache in HTTP Response header?如何在 HTTP 响应标头中发送 Cache-Control: no-cache?
【发布时间】:2011-08-30 11:42:29
【问题描述】:

Net 4 和 C#。

我需要在 Web 表单页面的 HTTP 响应标头中设置发送到浏览器缓存控制 (Cache-Control: no-cache)。

知道怎么做吗?

感谢您的宝贵时间。

【问题讨论】:

    标签: c# asp.net http-headers


    【解决方案1】:

    试试这个:

    Response.AppendHeader("Cache-Control", "no-cache");
    

    但是,您应该知道,仅此标头不会为您提供可靠的跨浏览器方法来防止缓存。请参阅此答案以获得更准确的解决方案:Making sure a web page is not cached, across all browsers

    【讨论】:

      【解决方案2】:

      在MVC中你可以在Controller类中设置,这样View就不用缓存了;

      public ActionResult User()
      {
          Response.CacheControl = "no-cache";
          return View();
      }
      

      【讨论】:

        【解决方案3】:

        对于 dotnet 核心:

        Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
        

        【讨论】:

          猜你喜欢
          • 2012-10-09
          • 2022-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-24
          • 2019-01-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多