I'm having a problem with page level output caching and vary by custom in our .NET 4.0 ASP.NET Web Forms application.
We use URL Rewriting so I wanted to vary the cache based on the raw url as different urls map to the same aspx handler page. (e.g. /article-1.aspx and /article-2.aspx both get handled by /articlepage.aspx)
I've tried
<%@ OutputCache Duration="60" VaryByParam="None" VaryByCustom="RAWURL" Location="Server" %>
and
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetVaryByCustom("RAWURL");
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
I've disabled the session and checked that we are not setting any cookies (in code and in Fiddler)
When I remove the VaryByCustom, caching works, but because of the URL Rewriting the content obviously doesn't match the URL.
The GetVaryByCustomMethod is simple
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom == "RAWURL")
{
return context.Request.Current.RawUrl;
}
else
{
return base.GetVaryByCustomString(context, custom);
}
}
It doesn't matter what I put in this method, even if I just get it to call the base class caching stops working.
We successfully use this technique for control level output caching, it just fails for page level.
I've created a simple site and got VaryByCustom working so there is clearly something else in this site preventing it.
Is there any tracing/logging I can do to see where the problem is?