【问题标题】:Disable ASP.net Cache禁用 ASP.net 缓存
【发布时间】:2011-03-11 23:10:24
【问题描述】:

有没有办法在所选页面上禁用 asp.net 缓存。如果可以从 web.config 中完成,那就太好了。

【问题讨论】:

    标签: c# .net asp.net vb.net


    【解决方案1】:
    Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();
    

    【讨论】:

      【解决方案2】:

      可以,如果您愿意创建自己的配置部分:http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

      在你的配置部分放一些类似的东西,

      <cachingConfig>
          <path>/Navigation/Menu.aspx</path>
          <path>/Target/Console.aspx</path>
          <path>/Target/Charting/Chart.aspx</path>
      </cachingConfig>
      

      您可以根据需要添加更多属性,例如持续时间。

      然后,在页面的 page_Init 方法中,检查此配置部分并在适当的地方调用以下内容:

      Response.Cache.SetCacheability(HttpCacheability.NoCache)
      

      编辑:提示:将初始化代码放在您的页面继承的基类中,这样它就只有一个地方。

      【讨论】:

        【解决方案3】:
        <!-- In the page itself -->
        <%@ OutputCache Location="None" %>
        

        或者

        // In the code-behind
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        

        不幸的是,它必须在页面内完成。从 web.config 中没有简单的方法可以做到这一点。欲了解更多信息,请查看:

        MSDN - Setting the Cacheability of a Page

        【讨论】:

          猜你喜欢
          • 2011-10-15
          • 2018-06-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-09-10
          • 2017-07-13
          • 2014-08-12
          • 2011-11-03
          相关资源
          最近更新 更多