I'm developing a website with MVC 5.2.3, it has a top menu bar in _Layout.cshtml that contains logged in user information. Like user's FullName, so it shouldn't be cache.
For exclude this menu from OutPutCache, I created a child action for it.
[ChildActionOnly]
public PartialViewResult TopMenu()
{
return PartialView("~/Views/Partials/TopMenuPartial.cshtml");
}
After that, I installed MvcDonutCaching nuget package and use it in _Layout.cshtml as the following:
@Html.Action("TopMenu", "Home", true)
But, it doesn't work, and if someone login, it's FullName came in top menu bar for all clients.
How should I remove this child action from MVC OutPutCache
I found the problem,
I didn't use
DonutOutputCacheattribute for output cache on actions, I usedOutPutCacheinstead.I changed it to
DonutOutputCache, and add the following setting inApplication_StartNow, my problem solved.