Missing web page context data. If required use IWebPageDataContextInitializer.Initialize

June 11, 2024 2:12 PM

I have error pages that are using custom routing rather than content tree-based routing. These error page has page builder enabled. Having editable areas on this page that has a custom route is causing the following error:

Missing web page context data. If required use IWebPageDataContextInitializer.Initialize method to initialize the context manually. For POST actions use HtmlHelper extension method Html.Kentico().PageData() to persist the page context.

I have tried adding page data context by adding the following code to the controller, but this did not fix the issue.

        var pageDataContext = webPageDataContextRetriever.Retrieve().WebPage;
        webPageDataContextInitializer.Initialize(pageDataContext);

Has anyone else ran into this issue? Any help would be much appreciated!


Environment

  • Xperience by Kentico version: [29.1.0]
  • .NET version: [8]
  • Deployment environment: [SaaS|Azure|VM]

Answers

If you aren't using Content Tree routing then it is your responsibility to tell Xperience which content tree page is associated with the given URL. How else would it know 🤷?

Why does it need this information? Well, all Page Builder configuration is persisted into the web page item's widget field (stored in CMS_ContentItemCommonData.ContentItemCommonDataPageBuilderWidgets and CMS_ContentItemCommonData.ContentItemCommonDataPageTemplateConfiguration in the database).

Without knowing which web page item is being requested, the widgets cannot be rendered or modified.

You can construct a RoutedWebPage (pageDataContext) manually, having queried for the web page item details from the database yourself, and populate it.

Then you can pass that RoutedWebPage to webPageDataContextInitializer.Initialize(pageDataContext); before the Razor view is executed.


To answer this question, you have to login first.