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

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

有没有办法使用OutputCache属性来缓存仅注销用户的结果并重新评估登录用户示例: 我想要什么 [OutputCache(onlycacheanon = true)]public ActionResult GetPhoto(id){ var photo = getPhoto(id); if(!photo.issecured){ return photo… }

有没有办法使用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
}

解决方法

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

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

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

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/kaifa/asp-net/20201019/11477.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部