Site icon Constellation for Sitecore

Reliable 404 support for your Sitecore installation

Sitecore off-the-shelf does not provide an end-to-end solution for the dreaded “Page Not Found”. The first 10 search results for “sitecore 404” demonstrate that this is an evergreen blogging topic for Sitecore developers. Popular solutions that were authored years ago still appear in the top 10! The fact that Stack Exchange is also in the top 10 shows that this remains a hot topic.

In 15 years of managing Sitecore development teams, rescuing, or inheriting outside Sitecore installs, broken 404 implementations abound. As usual, Sitecore’s flexibility becomes a liability for less experienced teams.

Constellation.Foundation.PageNotFound solves this problem for good, with no side-effects. Here’s why:

How it works

As you might expect, there’s an HttpRequestBegin pipeline processor that runs after all Item Resolution but before Sitecore starts picking things like Devices and Layouts. If the Context Item is null, the pipeline looks to see if the Context Site has an ID for the 404 page and makes the 404 page the Context Item. The pipeline then proceeds as normal, except….

Sitecore has a seldom used HttpRequestEnd pipeline, where we’ve got another processor! We check to see if the ID of the Context Item (if present) is the ID of the Context Site’s 404 page. If so, it adds the “404 not-found” status code to the response. no mess, no fuss, no MVC-level coding required, no special Renderings to insert. It just works.

Interested? You can read up on it here, install the NuGet package, or review the source code on GitHub.

Exit mobile version