ASP.Net Outputcache programmatically not working in partial view
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.
精彩评论