Kentico Xperience Page Builder: Troubleshooting tips
Tags: kentico, xperience, pagebuilder, troubleshooting
Published: 2021-02-05 14:38:19

##Introduction
One of Kentico Xperience's most powerful features :muscle: is the built-in Page Builder. When the Page Builder is activated, content editors and marketers are given a tool :toolbox: to enrich the digital platform with building blocks :package: in the form of Kentico Widgets.

When the Page Builder is running, features such as A / B testing :test_tube: and personalization become a breeze to use. It's a **must have** in any Kentico Xperience project.

Because their are a variety of ways to setup your solution architecture in ASP.NET Core MVC, e.g. pick and choose core components like the preferred dependency injection :syringe: framework, the Page Builder may not work immediately. In this post I will provide troubleshooting tips :bulb: to check and get the Page Builder working in your Kentico Xperience project.

##:heavy_check_mark: Checklist for troubleshooting
* Check if the **Page tab** is visible/accessible for the content item *#duh*
* Check if you can **create a new content item** with Page Builder enabled
* Check if the **Preview mode** works and shows the content item
 * Check if the **Page type URL Pattern** is set correctly
 * Check if **CMSHashStringSalt** value matches in CMS and MVC
 * Check and **re-sign Macro signatures**
 * Check length of **maxUrlLength** within **httpRuntime**
* Check for **Javascript errors** using the browser console
 * Check the **Content-Security-Policy** for blocked resources 
 * Check for **Cross-Origin Resource Sharing (CORS)** errors
 * Check for potential conflicts with **jQuery**
* Check if the CMS and MVC run on the [same hotfix](https://devnet.kentico.com/articles/kentico-12-mvc-page-preview-404-errors-troubleshooting-tips) version
* Check if the combination of CMS and MVC URLs [match correctly](https://docs.xperience.io/configuring-xperience/managing-sites/setting-domain-names-for-sites)
* Check for relevant errors in the **Event Log**
* Check the [fixed bugs](https://devnet.kentico.com/download/hotfixes) regarding Page Builder on Kentico DevNet
 * Check the **CMSPreviewLinkExpiration** setting (since 12.0.47)
* Check and review [Page Builder development](https://docs.xperience.io/developing-websites/page-builder-development) areas
 * Check if Page Builder is enabled in **Application_Start** 
 * Check if Page Builder is enabled **before** registered **routes**
 * Check for Page Builder namespace in **Views\web.config** 
 * Check for [Page Builder initialization](https://docs.xperience.io/developing-websites/page-builder-development/creating-pages-with-editable-areas#Creatingpageswitheditableareas-Initializingthepagebuilder) in **custom routes**
 * Check if [Editable areas](https://docs.xperience.io/developing-websites/page-builder-development/creating-pages-with-editable-areas) and [Sections](https://docs.xperience.io/developing-websites/page-builder-development/developing-page-builder-sections) are setup correctly
 * Check if Page Builder **scripts** and **styles** are present
* Check if your **custom URL module** is blocking Kentico system URLs
 * Check for paths **/cmsctx** and **/Kentico.***

##:boom: Potential error messages
**Error message #1:**
`The page builder feature is not enabled. You need to call the 'UsePageBuilder()' method of the Kentico.Web.Mvc.ApplicationBuilder instance at the start of your application's life cycle.`

**Error message #2:**
`An error occurred while attempting to retrieve page templates. Contact your system administrator and check that the page builder feature is registered correctly in the MVC project.`

**Error message #3:**
`This preview URL has already expired. Please contact a responsible person to provide you with a valid preview URL.`

**Error message #4:**
`Error: Request failed with status code 404 in builder.js or vendors.js`

**Error message #5:**
`Refused to frame 'https://www.yourdomain.com' because an ancestor violates the following Content Security Policy directive: "frame-ancestors https://admin.yourdomain.com https://www.yourdomain.com".`

**Error message #6:**
`Access to XMLHttpRequest at '...' from origin '...' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

**Error message #7:**
`Message: The '...' default section identifier doesn't represent registered section.`

##:briefcase: Specific fix when using Simple Injector
There was one error message which was very specific to our setup: 

**Error message #8:**
`A single instance of controller 'Kentico.PageBuilder.Web.Mvc.Internal.KenticoComponentDefaultController' cannot be used to handle multiple requests.`

In our Solution Architecture we used Simple Injector as our preferred Dependency Injection framework. Initially the Page Builder seemed to work up until we introduced Page Templates with multiple editable areas.

This can be solved by changing the Lifestyle of the internal called KenticoComponentDefaultController to Transient:
```csharp
container.Register(() => new KenticoComponentDefaultController(), Lifestyle.Transient);
```
This change alone is not enough, because the controller implements IDisposable. This results in the following error message: 

**Error message #9:**
`The configuration is invalid. The following diagnostic warnings were reported: -[Disposable Transient Component] KenticoComponentDefaultController is registered as transient, but implements IDisposable.`

The issue can be fixed as follows:
```csharp
container.RegisterDisposableTransient<KenticoComponentDefaultController, KenticoComponentDefaultController>();
```

For more information see the [Simple Injector documentation](https://simpleinjector.readthedocs.io/en/latest/disposabletransientcomponent.html).

##Summary
There are a lot of areas that interact with the Page Builder and therefore there can be many reasons why the Page Builder might not work. Hopefully with this post I have outlined an approach to quickly find the root cause. Feel free to share your Xperiences :wink: in the comments.