Errors when an .ASPX file for a layout is missing


Description

The following error may be raised when accessing content items that are configured to use a layout item referring to a non-existing .ASPX file.
ERROR Application error.
Exception: System.Web.HttpException
Message: The file '/layouts/MyLayout.aspx' does not exist.
Source: System.Web
   at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Solution 1

Ensure that the layout item used by the item points to a valid .ASPX file.

Solution 2

Perform the following steps if you would like Sitecore to redirect the user to the “Layout not found” page instead of showing an application error:
  1. Place the attached Sitecore.Support.389964.dll in the bin folder.
  2. Add the following processor to the httpRequestBegin pipeline, after the LayoutResolver processor:
    <httpRequestBegin>
    ...
    <processor type=”Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel”/>
    <processor type="Sitecore.Support.Pipelines.HttpRequest.LayoutFileResolver, Sitecore.Support.389964"/>