AI OnAI Off
Try something like this (note I haven't tried this code myself when I write this):
// filterContext variable is of type ControllerContext var currentContent = filterContext.HttpContext.Request.RequestContext.GetRoutedData<IContent>();
var contentRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<ContentRouteHelper>(); var content = contentRouteHelper.Content; if (content == null || !(content is CatalogContentBase)) { return; }
Hi,
I’m currently working on donut hole caching for our project. In order to generate correct cache keys in the ActionFilterAttribute I need to get current content from ControllerContext. I found multiple blog posts and answers that say you can get it like this: filterContext.Controller.ControllerContext.RouteData.Values["currentContent"]. There is even a demo project of donut hole caching for EPiServer that uses this logic: https://github.com/jondjones/JonDJones.Com.EpiServerDonutCaching/blob/master/JonDJones.Com.DonutHoleCaching/EpiServerDonutHelper.cs at line 77. However, the problem is, that I never get anything else in the RouteData besides language, partial, action and controller (please look at the picture attached: http://i350.photobucket.com/albums/q401/villu89/image001_zpsz5ptj0gw.png). Was this something that has been changed recently so it’s not in RouteData anymore? How can I get current content? We are using CMS.Core 10.3.1 and Commerce 10.2.1.