Is it possible to change the output cache in MVC based on specific values in a session? I read a lot about using the differentbycustom function and overriding GetVaryByCustomString in Global.asax, but the session is currently unavailable.
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (custom == "somekey")
return base.GetVaryByCustomString(context, custom);
}
I understand that this is due to the fact that the session is not fully created in the request pipeline.
I am worried that without changing the cache based on the user session, the page (which changes depending on what the user has in the session, has additional HTML specific to that user, etc.) will be cached (as the URL) and is served by our load balancer, proxy servers, etc., and then served by other requests with information about other users on the page!
The reason the URL is the same is because the user logs in as a “guest”, enters some information (POST), it is checked and saved in the session, and then redirected back to the same page (which should now be user-specific based on session data).
The page itself should be cached normally, because if a "guest" visits the same URL, it must serve the same "standard" page each time.
Is it possible to change caching this way?
source
share