asp.net-mvc-3 - outputcache mvc3 仅对注销用户进行缓存

标签 asp.net-mvc-3 outputcache

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

相关文章:

asp.net-mvc-3 - 刷新页面后,TempData变为空

c# - MVC 3 - 将 ViewBag 内容分配给 Javascript 字符串

c# - 在 asp.net mvc 中以编程方式中止 OutputCache 持续时间

c# - 使用 ASP.NET MVC OutputCache,同时根据用户是否经过身份验证改变 View 内容

asp.net-mvc - MVC OutputCache for Child Actions : where is it stored?

c# - 当单个部分需要多个对象时,如何从 View 中动态地将项目添加到我的集合中?

c# - 在字符串上使用 Razor 引擎 - 而不是 View

c# - 无法加载文件或程序集 ICSharpCode.SharpZipLib ...使用 nuGet 包 ExcelDataReader 时

asp.net - 标准 OutputCache 属性是每个用户还是每个应用程序

c# - 使用自定义 Redis 输出缓存提供程序时 MVCDonutCaching 失败