EPiServer Content Folders ‘For All Sites’, ‘For This Site’, ‘For this Page’ not showing up in edit mode

I was investigating a failing Selenium test the other day and ran into a bit of trouble. It occured as the EPiServer content database template had been restored and EPiServer was loading the site for the first time after an application pool recycle (For more information on the template database testing environment, please see this article: Keeping reliable test data in EPiServer content database for automated UI tests).

EPiServer ContentNotFoundException thrown when starting the EPiServer website.

EPiServer Forms’s SetupRootFolderForForm failing when SiteBlockFolder is null

Further investigation using ILSpy led me to a method in the EPiServer.Forms.EditView.InitializationModule called SetupRootFolderForForm.

Part of method SetupRootFolderForForm()

if (flag4)
{
  InitializationModule._logger.Information( "SetupRootFolderForForm: We need to create new folder as root for storing Form's Blocks");
  ContentFolder @default = this._contentRepository.Service.GetDefault<ContentFolder>(ContentReference.SiteBlockFolder);
  @default.Name = InitializationModule._formConfig.Service.RootFolderName;
  this._contentRepository.Service.Save(@default, SaveAction.Publish, AccessLevel.NoAccess);
  InitializationModule._formConfig.Service.RootFolder = @default.ContentLink.ToReferenceWithoutVersion();
}

The exception was thrown because the ContentReference.SiteBlockFolder (line 4) was set to non-existing content for one of our two websites in the EPiServer installation; i.e. a content with id 501, which didn’t exist in our template database.

Reverting the code base to a pre-EPiServer Forms commit, and having a look in EPiServer’s edit mode confirmed this. The left pane in the image below is the site with the faulty SiteBlockFolder reference, and the right one is the site where everything was working as it should.

Content Folders For All Sites, For This Site, For This Page not showing up in EPiServer edit mode.

Resetting EPiServer’s Content Folders to get ‘For All Sites’, ‘For This Site’, ‘For this Page’ back

The solution is rather simple. In EPiServer’s Admin mode (Config tab, and Manage Websites option) you have a checkbox called Use site-specific assets if you access the non-working website’s settings. Thanks Thomas Durrani.

EPiServer's administration mode with site-specific assets option.

Simply click it, save the settings, click it again and save – and your references should be repaired by the EPiServer installation.

EPiServer edit mode with working Content Folders for multisite environment.

This is also confirmed if we have a look in the EPiServer database table tblSiteDefinition.

EPiServer database table tblSiteDefinition with working ids.

The first website was the one with the faulty reference. It’s SiteAssetsRoot value was previously set to 501, but was automatically changed to the working reference 542.

Exception Details: EPiServer.Core.ContentNotFoundException: Content with id 501 was not found

[ContentNotFoundException: Content with id 501 was not found]
   EPiServer.Core.DefaultContentLoader.Get(ContentReference contentLink, LoaderOptions loaderOptions) +536
   EPiServer.Core.DefaultContentRepository .GetDefault(ContentReference parentLink, Int32 contentTypeID, CultureInfo language) +252
   EPiServer.Forms.EditView.InitializationModule .SetupRootFolderForForm() +1036
   EPiServer.Forms.EditView.InitializationModule .Initialize(InitializationEngine context) +263
   EPiServer.Framework.Initialization.Internal.ModuleNode .Execute(Action a, String key) +64
   EPiServer.Framework.Initialization.InitializationEngine .InitializeModules() +387

One Response

  1. Simon Lawson March 21, 2017