Software Engineer, Sitecore Certified Trainer & Expert
26. Februar 2015
Today I Learned Part 3
Today I learned…
… that if you want to configure an SEO optimized “page not found” url, you can’t use the config setting “RequestErrors.UseServerSideRedirect” in Sitecore MVC.
That’s because of the MVC routing, which than throws an exception. I couldn’t find a way to prevent that from happening and had to fiddle with the pipelines again.
To keep the incorrectly typed URL and display the 404 page to the user, I created a new piepeline process which sets the “Sitecore.Context.Item” to the configured page not found URL.
public class NotFoundResolver : HttpRequestProcessor
public override void Process(HttpRequestArgs args)
if (Sitecore.Context.Item != null)
var notFoundUrl = Sitecore.Configuration.Settings.ItemNotFoundUrl;
if (Sitecore.Context.Database == null || String.IsNullOrEmpty(notFoundUrl)) return;
var notFound = Sitecore.Context.Database.GetItem(string.Concat(Sitecore.Context.Site.StartPath, notFoundUrl));
if (notFound == null)
Sitecore.Context.Item = notFound;
And finally to set the correct http status code to 404, I created a controller rendering in which I return a “HttpNotFoundResult”.
public ActionResult SetStatusCode()
return new HttpNotFoundResult();
You can easily extend this approach by, for example, getting the not found url from the site settings.