asp.net-mvc-3 – outputcache mvc3只注销了用户缓存

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – outputcache mvc3只注销了用户缓存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法使用OutputCache属性来缓存仅注销用户的结果并重新评估登录用户示例:

我想要什么

  1. [OutputCache(onlycacheanon = true)]
  2. public ActionResult GetPhoto(id){
  3. var photo = getPhoto(id);
  4. if(!photo.issecured){
  5. return photo...
  6. }
  7. return getPhotoOnlyIfCurrentUserHasAccess(id);
  8. //otherwise return default photo so please don't cache me
  9. }

解决方法

您可以在[OutputCache]中使用VaryByCustom属性.

然后覆盖HttpApplication.GetVaryByCustomString并检查HttpContext.Current.User.IsAuthenticated.

>如果未经过身份验证,则返回“NotAuthed”或类似内容(激活缓存)> Guid.NewGuid().ToString()使缓存无效

猜你在找的asp.Net相关文章