缓存内容仅对非认证用户 [英] Caching content only for non-authenticated users

查看:103
本文介绍了缓存内容仅对非认证用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个网站,我想缓存只对谁不认证用户的页面 - 身份验证的用户没有得到缓存的内容(因为他们将被更新,需要马上看到结果)

For a web-site, I want to cache the pages ONLY for users who are not authenticated - authenticated users do not get cached content (since they will be updating and need to see results right away).

我知道如何改变使用VaryByCustom是每个用户缓存:
<一href=\"http://visitmix.com/LabNotes/Using-VaryByCustom-With-OutputCache-in-ASPNET-MVC-To-Support-Caching\"相对=nofollow>链接1
<一href=\"http://stackoverflow.com/questions/1256317/how-not-cache-an-asp-net-user-control\">Link2

I know how to vary the cache for each user using VaryByCustom: Link1 Link2

...但我不能想出如何完全关闭缓存身份验证的用户。

...But I can't figure out how to turn off caching entirely for authenticated users.

该怎么办?

修改

下code的,如果已经有来自未认证用户的页面的缓存版中的问题。基本身份验证的用户将被送达事物的未经验证的视图。

The code below has a problem if there is already a cached version of the page from an unauthenticated user. Basically the authenticated user will be served the unauthenticated view of things.

不过,这个环节在这里有解决方案,它的工作原理:<一href=\"http://stackoverflow.com/questions/2109928/how-to-turn-output-caching-off-for-authenticated-users-in-asp-net-mvc\">Link

However, this link here has solution that works: Link

推荐答案

使用HttpCachePolicy.AddValidationCallback。

Use HttpCachePolicy.AddValidationCallback.

请参阅:的http://msdn.microsoft.com/en-us/library/system.web.httpcachepolicy.addvalidationcallback.aspx

这篇关于缓存内容仅对非认证用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆