【问题标题】:Remove ChildAction from OutPutCache in MVC 5?从 MVC 5 中的 OutPutCache 中删除 ChildAction?
【发布时间】:2016-04-16 20:01:33
【问题描述】:

我正在使用 MVC 5.2.3 开发一个网站,它在_Layout.cshtml 中有一个顶部菜单栏,其中包含登录的用户信息。像用户的全名一样,所以它不应该被缓存。
为了从 OutPutCache 中排除这个菜单,我为它创建了一个子操作。

[ChildActionOnly]
public PartialViewResult TopMenu()
{
    return PartialView("~/Views/Partials/TopMenuPartial.cshtml");
}

之后,我安装了MvcDonutCaching nuget 包并在_Layout.cshtml 中使用它,如下所示:

@Html.Action("TopMenu", "Home", true)

但是,它不起作用,如果有人登录,它的 FullName 会出现在所有客户端的顶部菜单栏中。

我应该如何从 MVC OutPutCache 中删除这个子操作

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-5 outputcache donut-caching


    【解决方案1】:

    我发现了问题,
    我没有使用DonutOutputCache 属性作为动作的输出缓存,而是使用OutPutCache
    我改成DonutOutputCache,在Application_Start中添加如下设置

    protected void Application_Start()
    {
    ...
    DevTrends.MvcDonutCaching.OutputCache.DefaultOptions = DevTrends.MvcDonutCaching.OutputCacheOptions.ReplaceDonutsInChildActions;
    ...
    }
    

    现在,我的问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 2017-04-25
      • 1970-01-01
      • 2018-02-01
      相关资源
      最近更新 更多