I'm using OutputCache in my page that has a user control, but I don't want to cache this specific user control because it's related to a user login (if I access the page, I see the page as if I were authenticated with another user).
How can I do that?
You can cache a page and you can cache a user control, but you can't cache a page except for a user control. When the user control runs the entire page has to run. You have to make the output cache for the page recognise the different users.
You can use
VaryByHeader="Cookie"
to cache the page for each set of cookies if the user identity is stored in a cookie. You can useVaryByCustom="SomeString"
and implement a check forSomeString
to do your own check for user identity in theGetVaryByCustomString
method inGlobal.asax
.You can create a cache filter : http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx
Check inside this filter if the user is logged or not.
Personally I use the VaryByCustom attribute to give logged in and logged out users different cached page views:
then in global.asax you put
I am just going to throw this out there. How about the substitution control?
http://msdn.microsoft.com/en-us/library/ms228212.aspx
According to msdn website:
I have never used the substituion control personally, but I just happened to look it up the other day, and it sounded like it can somehow inject updated content into an otherwise cached page output.