My website have a home page, and I would like to cache that page for anonymous users, and set it as "private" for authenticated users (so they save it on their computers, nowhere else).
So, if the user is anonymous I want to save the page in the server cache, and also in the browser cache using Cache-control:public, max-age=60
and Vary:Cookie
, so if the browser gets authenticated and send a cookie, the browser won't reuse the former stored page.
If the user is authenticated, then I do not want the page be stored in the server, but I do on the customer browser using Cache-control:private, max-age=60
.
I have been trying with several combinations with OutputCacheAttribute and Response.Cache but I cannot get it right.
What would be the best way of doing it?
Regards.
You may try implementing a
VaryByCustom
rule that will distinguish between anonymous and authenticated users. Here's an example that should put you on the right track.