在ASP.NET MVC 3个非认证用户缓存主页 [英] Cache home page for non-authenticated users in ASP.NET MVC 3
问题描述
我的网站有一个主页,我想缓存为匿名用户的页面,并将其设置为私人认证用户(因此他们将其保存在自己的电脑,无处)。
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).
因此,如果用户是匿名我要保存网页服务器缓存,并且还使用缓存控制浏览器的缓存:公众,最大年龄= 60
和因人而异:饼干
,因此,如果浏览器获得认证,并发送一个cookie,浏览器将不会重复使用前存放页
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.
如果用户通过验证,那么我不想要的网页保存在服务器上,但我使用缓存控制用户的浏览器:私人,最大年龄= 60
。
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
.
我一直在试图与OutputCacheAttribute和Response.Cache几个组合,但我无法得到它的权利。
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?
问候。
推荐答案
您可以尝试实施 VaryByCustom是
规则,将匿名和身份验证的用户加以区分。这里的<一个href=\"http://visitmix.com/writings/using-varybycustom-with-outputcache-in-asp-net-mvc-to-support-caching-for-logged-in-users\"相对=nofollow>一个例子应该把你在正确的轨道上。
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.
这篇关于在ASP.NET MVC 3个非认证用户缓存主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!