SaaS CMS has officially launched! Learn more now.

How to get current content from executing context?



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: 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: 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.

Edited, Mar 09, 2017 16:03

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>();

Edited, Mar 13, 2017 16:20
var contentRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<ContentRouteHelper>();
            var content = contentRouteHelper.Content;
            if (content == null || !(content is CatalogContentBase))
Mar 13, 2017 18:01

Hi! Thank you for the answers! Seems like both methods work just fine!

Apr 04, 2017 8:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.