【发布时间】:2014-03-10 01:44:10
【问题描述】:
问题是:当用户访问 Default.aspx 时,页面加载了 Blog.ascx 内容的缓存版本(因为它在 600 秒内再次访问了同一页面),因此没有执行 Page.Title 代码标题保持为空,而不是像第一次新加载页面时那样有<title>Title of Blog Post</title>。
我的 asp.net 网站有 Blog.ascx 来处理加载单个博客文章的内容。 Default.aspx 包含对 Blog.ascx 的引用并使用 Blog.ascx 页面具有自定义缓存:
<%@ OutputCache Duration="600" VaryByParam="None" VaryByCustom="Url" %>
位于 global.asax.cs 的自定义缓存是:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
switch (custom.ToUpper())
{
case "URL":
return context.Request.Url.ToString().ToLower().Trim();
default:
throw new NotImplementedException();
}
}
Blog.ascx.cs Page_Load 事件处理程序化标签的值/内容
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "Title of Blog Post";
}
有什么建议吗?
【问题讨论】:
-
你无法避免这个问题 - 你需要重新设计你的想法以使其发挥作用,要么删除缓存,要么将标题保存在主页上,要么对渲染进行自定义缓存。