max*_*dbe 6 outputcache asp.net-mvc-3
有没有办法使用OutputCache属性来缓存仅注销用户的结果并重新评估登录用户示例:
我想要什么
[OutputCache(onlycacheanon = true)]
public ActionResult GetPhoto(id){
var photo = getPhoto(id);
if(!photo.issecured){
return photo...
}
return getPhotoOnlyIfCurrentUserHasAccess(id);
//otherwise return default photo so please don't cache me
}
Run Code Online (Sandbox Code Playgroud)
您可以使用该VaryByCustom物业[OutputCache].
然后重写HttpApplication.GetVaryByCustomString并检查HttpContext.Current.User.IsAuthenticated.
"NotAuthed"如果未经过身份验证,则返回或类似(激活缓存)Guid.NewGuid().ToString() 使缓存无效