Page Not Found Module

Constellation.Foundation.PageNotFound is a library for providing consistent, site-specific 404-page support to your Sitecore installation.

Although there are many pages available online that explain how to set up a “not found” page in Sitecore, it’s one of the most common things I find broken when diagnosing/evaluating customer installs. This library will turn the 404 page creation process into a “fire & forget” developer task with good results every time.

What’s in the Box

  • Each site in your installation will have its own 404 page.
  • The 404 page will be a plain-old Sitecore-managed Item, with its own content and presentation details.
  • The 404 page will support the Context Language of the request.
  • When Sitecore responds with the 404 page, it will correctly set the Response header with the 404 “not found” status code.
  • There are no special Renderings or View tricks required to get Sitecore to respond with the 404 status code.
  • Developers need to make only one small configuration file change for each site that will need a 404 page.

Installation

Constellation.Foundation.PageNotFound is managed via NuGet.

In Visual Studio, fire up the Package Manager console and install into a Web Application project:

PM:> Install-Package Constellation.Foundation.PageNotFound

After installation, build & deploy your solution. You now have the critical infrastructure to support proper “404” pages.

Configuring 404 Pages

In order to activate this feature, you need to perform the following:

Create your 404 Page Item in Sitecore

You can use whatever page templates you already have set up. The page must be created, edited, and published. Note the Item ID of your 404 page; it is required by the next step.

Edit your <site/> Configuration Element

You need to register a 404 page ID for each site in your installation. Here is an example of an XML patch for the “website” site element:

<site name="website">
<patch:attribute name="notFoundPageID">{11111111-1111-1111-1111-111111111111}</patch:attribute>
</site>

After making the above configuration patch, rebuild & deploy your code. Your 404 page should now be active, and should return a 404 response.

Finesse

I would strongly consider changing the Item Access permissions for each site’s 404 page. Explicitly Deny the “delete” right to prevent your hard work from being unintentionally undone.

Next Steps

Make sure every site in your installation has a 404 Not Found page! If you’re interested in checking out the source code, it’s available on GitHub.

A big Thank You goes out to Verndale for providing some of the basics for this module and for allowing it to be included in the Constellation!