Cache home page for non-authenticated users in ASP.NET MVC 3

醉酒当歌 提交于 2020-01-03 16:04:21

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/9180954/cache-home-page-for-non-authenticated-users-in-asp-net-mvc-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!