有没有办法使用 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
}
最佳答案
您可以使用VaryByCustom
属性(property) [OutputCache]
.
然后覆盖HttpApplication.GetVaryByCustomString并检查HttpContext.Current.User.IsAuthenticated
。
- 返回
"NotAuthed"
或类似的如果未经过身份验证(激活缓存) -
Guid.NewGuid().ToString()
使缓存无效
关于asp.net-mvc-3 - outputcache mvc3 仅对注销用户进行缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9901866/