开发者

ASP.Net Outputcache programmatically not working in partial view

开发者 https://www.devze.com 2023-01-04 08:51 出处:网络
The following code is not working in a partial view. <% // Pages always expire at midnight. Response.Cache.SetExpires(DateTime.Today.AddHours(24));

The following code is not working in a partial view.

<%
  // Pages always expire at midnight.
  Response.Cache.SetExpires(DateTime.Today.AddHours(24));

  if (variable > 0)
  {
      Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
  }
  else
  {
      Response.Cache.SetCacheability(HttpCacheability.Public);
  }
%>

Can anyone tell me why? The partial view is never cached a开发者_运维问答nd there is no apparent reason. Should I write code to activate the cache? How?


Try putting the code into the control's codebehind file Page_Load or Page_Init event. I suspect that because your code is inline in your ascx file, it is being executed too late in the lifecycle of the control.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号