Umbraco runs all content finders in the collection 'in order', until one of the IContentFinders returns true, and then the request is handled by that finder, and no further IContentFinders are executed. Therefore the order in which ContentFinders are added to the ContentFinderCollection is important.

The ContentFinder can set the PublishedContent item for the request, or template or even execute a redirect…

Example

This IContentFinders will find a document with id 1234, when the Url begins with /woot

Adding and removing IContentFinders

Use a composer to access the ContentFinderCollection to add and remove specific ContentFinders...

using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespaceMy.Website
{
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
publicclassUpdateContentFindersComposer : IUserComposer
{
publicvoidCompose(Composition composition)
{
//add our custom MyContentFinder just before the core ContentFinderByUrl...
composition.ContentFinders().InsertBefore<ContentFinderByUrl, MyContentFinder>();
//remove the core ContentFinderByUrl finder:
composition.ContentFinders().Remove<ContentFinderByUrl>();
//you can use Append to add to the end of the collection
composition.ContentFinders().Append<AnotherContentFinderExample>();
//or Insert for a specific position in the collection
composition.ContentFinders().Insert<AndAnotherContentFinder>(3);
}
}
}

NotFoundHandlers

To set your own 404 finder create an IContentLastChanceFinder and set it as the ContentLastChanceFinder. (perhaps you have a multilingual site and need to find the appropriate 404 page in the correct language)

A ContentLastChanceFinder will always return a 404 status code. This example creates a new implementation of the IContentLastChanceFinder and checks whether the requested content could not be found by using the default Is404 property presented in the PublishedRequest class.

Our.umbraco.com is the community mothership for Umbraco, the open source asp.net cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community.
This site is running
Umbraco version 7.13.1