Content finders in Umbraco are really useful as they can intercept the routing and give you access to the context. There are a few uses of this and one on those is to find your page not found page that you have created especially in Umbraco. This differs from the more traditional way of setting a page id within your umbracoSettings.config file and is useful for giving your client complete control over their page not found page. So, in the example below, there would be a corresponding document type in Umbraco called NotFoundPage.

using System . Linq ;

using Umbraco . Core ;

using Umbraco . Core . Models ;

using Umbraco . Web ;

using Umbraco . Web . Routing ;



public class PageNotFoundContentFinder : IContentFinder

{

public bool TryFindContent ( PublishedContentRequest request )

{



if ( request . PublishedContent == null )

{



var home = request . RoutingContext . UmbracoContext . ContentCache . GetByRoute ( request . Domain . RootNodeId + "/" ) ;





var notFoundNode = home . Children . Where ( x => x . DocumentTypeAlias == "NotFoundPage" ) . FirstOrDefault ( ) ;

if ( notFoundNode != null )

{



request . SetResponseStatus ( 404 , "404 Page Not Found" ) ;





request . PublishedContent = notFoundNode ;

}

}





return request . PublishedContent != null ;

}

}