Try our conversational search powered by Generative AI!

PageContextActionFilter : filterContext.HttpContext.GetContentLink() is null even though model is not null.

Vote:
 

Hello,

In below method OnResultExecuting(), highlighted line for currentContentLink is returned null for some pages (even though page just loads fine, but there is error in local environment for currentContentLink null value) in CMS 12 migrated project but it works fine in CMS 11 project.

Can anyone help us with this? What might be causing this strange behaviour?

public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }
            var controller = filterContext.Controller as Controller;
            var viewModel = controller?.ViewData.Model;

            if (viewModel is IPageViewModel<SitePageData> model)
            {
                var currentContentLink = filterContext.HttpContext.GetContentLink();

                var layoutModel = model.Layout ?? contextFactory.CreateLayoutModel(currentContentLink, filterContext.HttpContext);

                if (filterContext.Controller is IModifyLayout layoutController)
                {
                    layoutController.ModifyLayout(layoutModel);
                }

                model.Layout = layoutModel;

                if (model.Section == null)
                {
                    model.Section = contextFactory.GetSection(currentContentLink);
                }
            }
        }

Thank you,

Deepa

#305101
Jul 13, 2023 7:43
Vote:
 

Check the GetContentLink method implementation: Ensure that the implementation of GetContentLink method in the HttpContext extension is correct and compatible with CMS 12. It's possible that there might be changes in the CMS 12 framework that require modifications to this method.

#305170
Jul 14, 2023 13:03
Vote:
 

Hi Deepa,

As I understand, The system is not able to return you content because it can't route the request to a piece of content https://world.optimizely.com/CsClassLibraries/cms/EPiServer.Web.Routing.HttpContextExtensions?version=12.

There for is there any customization around routing in your solution that is possibly causing an issue?

Paul

#305294
Jul 17, 2023 16:28
Vote:
 

Hello,

There is no customization around routing in our solution, it's fetching contentlink properly for almost all pages. But only for some pages it's returning null on that highlighted line.

Thanks,

Deepa

#305385
Jul 19, 2023 5:00
* 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.