【问题标题】:How to disable OutputCache for only one UserControl on a ASP.Net Page?如何在 ASP.Net 页面上仅为一个 UserControl 禁用 OutputCache?
【发布时间】:2011-02-04 03:19:12
【问题描述】:

我在 ASP.NET 页面上使用 OutputCache。我在我的 Page_Load 中以这样的方式设置它:

Response.AddFileDependency(cachefilepath);
Response.Cache.SetExpires(DateTime.Now.AddHours(12));
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetSlidingExpiration(false);
Response.Cache.VaryByParams["*"] = true;

现在页面将被缓存,这工作正常。但是我在页面上有一个不应被缓存的 UserControl。尽管整个页面正在被缓存,是否可以为此 UserControl 禁用缓存?

原因是此 UserControl 的输出有两种状态,因此每个客户端的操作可能会有所不同...

【问题讨论】:

    标签: asp.net caching outputcache


    【解决方案1】:

    Response.Cache 是每个网页的,您必须根据用户控件管理整个页面上的缓存,换句话说,当您的用户控件是动态的时,您必须使页面缓存过期,看起来像在您的案例页面输出缓存将无法正常工作

    或者您可以添加 VaryByControl 并传递该控件,参考:http://msdn.microsoft.com/en-us/library/hdxfb6cy.aspx

    【讨论】:

      猜你喜欢
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多