x First time here? Check out the FAQ

How to implement your own 404 handler

    In some scenarios the build in mechanism for the 404 handlers are not sufficient. But you can easily implement your own 404 handler. Just create a class which implements the umbraco.interfaces.INotFoundHandler interface. This interface defines two properties and one method. Let's assume you have several domains in your umbraco installation: www.domain1.com, www.domain2.com, www.domain3.com, etc. With the standard definitions in the /config/umbracoSettings.config you can only separate by language (en-US, de-DE, etc). In this case you would implement something like this:

    using System.Web;
    using umbraco.interfaces;

    namespace MyLibrary.Handlers
    {
    public class MyNotFoundHandler: INotFoundHandler
    {
    private int redirectId;

    public bool Execute(string url)
    {
    var server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();
    if (server == "www.mydomain1.com")
    {
    redirectId = 1234; // the id of the 404 and search page from domain1.com
    return true;
    }
    if (server == "www.mydomain2.com")
    {
    redirectId = 5678; // the id of the 404 and search page from domain2.com
    return true;
    }
    return false;
    }

    public bool CacheUrl
    {
    get { return false; }
    }

    public int redirectID
    {
    get { return redirectId; }
    }
    }
    }

    Explanation:

    The method Execute is the entry point to this handler and gets the requested url. But you can also use the HTTPContext with all the ServerVariables of the HttpRequest.

    If the handler finds a solution to redirect to another node you have to set the local redirectId variable which is read by the request handler if the Execute method returns true. If the Execute method returns false the two properties won't be read by the request handler and the next 404handler (if defined in the config) will be called.

    You can also define if this url with it's redirected id will be cached or not.

    Configuration:

    Be sure to add the dll to the bin folder and update the /config/404handlers.config.