new error message

lawrence whittemore asked on January 3, 2023 22:23

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

Getting this error when the site tries to load my error page.

any thoughts on what I could have done to cause this?

Recent Answers


Liam Goldfinch answered on January 4, 2023 10:01

Are you using a Controller to render the error page?

In the action method, are you calling:

_pageDataContextInitializer.Initialize(errorPage);

Sounds like you might not be, and the layout/masterpage depends on the page being initialized for some data to be accessed?

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on January 4, 2023 14:03

would that be a new thing? it has worked all along up until now.

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on January 4, 2023 14:22

This page data context initializer is new for Kentico Xperience 13, but it kind of replaces Kentico 12's way of initializing the page builder context:

HttpContext.Kentico().PageBuilder().Initialize(page.DocumentID);

If you are using content-tree based routing, page data context initialization is handled for you automatically by the system. But if you're using custom routing (which I guess you might be for your error controller) then you need to initialize the page data content manually.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on January 4, 2023 15:30

So it's starting to make sense. I did add a pagebuilder component on my _layout.cshtml. Should I just not have it there? The error page doesn't have any kentico page that corresponds to it.

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on January 4, 2023 15:42

What do you mean by pagebuilder component?

Have you added a widget inline in your _layout.cshtml? Is it a View Component trying to access the current page by IPageDataContextRetriever? Or something else?

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on January 4, 2023 20:47

I added this tag to the _layout.cshtml file <editable-area area-identifier="tourcode" />

is there a way to have the error page ignore it?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 4, 2023 22:11

You should NOT have those in your _layout.cshtml file. Those tags should be in a view or partial view from a controller's action or widget component. Back in PE days, you could add all you wanted to your "master page", but this is a bit different and doesn't work like that.

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on January 4, 2023 22:13

That's what I suspected and just moved it to a view.

Thanks! someday I'll be a Kentico master. :P

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.