ASP.NET MVC 3 中未经身份验证用户的缓存主页
我的网站有一个主页,我想为匿名用户缓存该页面,并将其设置为经过身份验证的用户的“私有”(以便他们将其保存在自己的计算机上,而不是其他地方)。
因此,如果用户是匿名的,我想将页面保存在服务器缓存中,并使用 Cache-control:public, max-age=60
和 Vary:Cookie 将页面保存在浏览器缓存中
,因此如果浏览器通过身份验证并发送 cookie,浏览器将不会重用以前存储的页面。
如果用户已通过身份验证,那么我不希望将页面存储在服务器中,但我会使用 Cache-control:private, max-age=60
在客户浏览器上存储页面。
我一直在尝试使用 OutputCacheAttribute 和 Response.Cache 的几种组合,但我无法正确使用。
最好的方法是什么?
问候。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试实施
VaryByCustom
规则来区分匿名用户和经过身份验证的用户。这是 一个示例应该会让您走上正轨。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.