页面级输出缓存无法与VaryByCustom一起使用

时间:2013-11-04 09:59:20

标签: c# asp.net caching webforms

我遇到了页面级输出缓存问题,并且在我们的.NET 4.0 ASP.NET Web窗体应用程序中因自定义而异。

我们使用URL重写,因此我想根据原始URL更改缓存,因为不同的url映射到相同的aspx处理程序页面。 (例如/article-1.aspx和/article-2.aspx都由/articlepage.aspx处理)

我试过

<%@ OutputCache Duration="60" VaryByParam="None" VaryByCustom="RAWURL" Location="Server"  %>

Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetVaryByCustom("RAWURL");
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));

我已禁用会话并检查我们是否未设置任何Cookie(在代码和Fiddler中)

当我删除VaryByCustom时,缓存有效,但由于URL重写,内容显然与URL不匹配。

GetVaryByCustomMethod很简单

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if (custom == "RAWURL")
    {
        return context.Request.Current.RawUrl;
    }
    else
    {
        return base.GetVaryByCustomString(context, custom);
    }
}

无论我在这个方法中放什么,即使我只是让它调用基类缓存停止工作。

我们成功地将此技术用于控制级输出缓存,它只是在页面级别上失败。

我创建了一个简单的网站并让VaryByCustom正常工作,因此该网站显然还有其它方法可以阻止它。

我可以做任何跟踪/记录来查看问题所在吗?

0 个答案:

没有答案
相关问题