ASP.Net Outputcache 以编程方式无法在部分视图中工作
以下代码在部分视图中不起作用。
<%
// 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);
}
%>
谁能告诉我为什么?部分视图永远不会被缓存,并且没有明显的原因。我应该编写代码来激活缓存吗?如何?
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 and there is no apparent reason. Should I write code to activate the cache? How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将代码放入控件的代码隐藏文件 Page_Load 或 Page_Init 事件中。我怀疑因为您的代码内联在 ascx 文件中,所以它在控件的生命周期中执行得太晚了。
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.