All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

Custom 404 Handler (CMS 4 and 5)

This library contains a custom 404 handler for your EPiServer CMS 4 or 5 project. It will replace the default 404 handler with one that you can change, in order for it to have a more consistent look with the rest of your site. It will also handle more 404 cases than the built-in handler.


  • Custom 404 FileNotFound page to replace the built-in error page
  • A powerful CustomRedirects module thats extends the built-in ShortCurUrl function
  • An admin plugin that shows all the CustomRedirects defined
  • FallBack url handling that allows all 404 requests to be redirected to a back-end server only if the url exists on that server

This module has a more advanced url redirect feature than the built-in shortcut url feature in EPiServer. It handles extensions and querystring parameters too. If you have a lot of 404 errors in your logs, you can use this to redirect the user to the correct page. Especially useful if you move templates or pages around, or have just installed EPiServer and have a lot of old urls that is no longer available.

To ease the transition to EPiServer for your existing visitors, this module also contains a fallback handler that will check if a failed request can be sent to a backup system (your old site for an example.) Use with care, as it can make 404 requests slow, especially when spiders hit your site.


See what the 404 page can look like


down.gif Download Now

Changing the notfound page

You can, and should, change the /bvn/filenotfound/notfound.aspx file to look somewhat like the rest of your site. The .aspx file is intentionally NOT an EPiServer template, to keep it clean and easy to troubleshoot. It uses text resources from the /lang directory. You can change the contents of the 404 page by editing the language files.

Please do not change and commit the notfound.aspx file directly in this library, make a copy of it and change that.

Keep the page simple, and if possible, avoid retrieving data from the database (like pages in EPiServer). The 404 page could be the result of a missing page in EPiServer and in worst case could lead to an infinite loop of 404 requests. Also make sure that your 404 handler itself does not trigger any new 404 errors by linking to graphics etc. that is missing (for the same reason).

Note! The source and configuration examples assume your site is a root relative site, not a virtual directory. If it is, you might have to change the code or configure the settings differently.

Custom Redirects

There are two types of redirects:

  1. Exact match The old url (the one not found) is matched. The redirect will be done to the new one.
  2. Beginning of string match In the code this is referred to as a wildcard match. This will be attemted if there is no exact match. All the old urls in the config file will be checked to see if they start with the same string as the url that cannot be found. This allow you to catch all not found urls that start with the same string, and redirect them to somewhere else, keeping the full url, but changing the domain. The path and query part of the url will be appended to the new url from the config file.

Example configuration file:

               This redirects within the same site.            
               This redirects to an old server. 
               Several out-dated urls can be redirected
               to the same new url.
               Old shortcut url to
               new shortcut url!
           <!-- Test to check that this should not
                go into a infinite loop -->
           <!-- You can also use site relative roots
                for your destination, as the redirect
                is done on the server.
       <!-- Usually, when a "beginning of string" match is found, the path
            and querystring of the old url is appended to the new one. This
        can be used to redirect all pages below a given path to an old
        server. If you do not want the string beeing appended, set the
        onWildCardMatchSkipAppend to true.     
           <old onWildCardMatchSkipAppend="true">/our_business/markets/transport</old>

There is also a plug-in for Admin mode to show the contents of this file.

Fallback Feature

In some cases, you want to keep the old site around for some time, to ease the transition. If you add a value to the EPsBvn404HandlerBackendRootUrl, the code will try to find the requested url on the backend server.

In a real life scenario you'd perhaps change the host name of the old site to www2.mysite.com, and roll out EPiServer on the www.mysite.com address. All browser favourites, links from other site etc. will then be broken (because of the new naming scheme of the site). With the fallback feature, an url like www.mysite.com/about/map.html would then automatically be redirected to www2.mysite.com/about/map.html, but only if that url exists. If the url is wrong or has been removed, the notfound page will be shown instead.

The Fallback feature invokes a web client request from the server to check if the backend actually recognizes the url. The result is then cached, and the next request for the same url will be redirected directly.

Note! This feature is only available in the EPiServer CMS 4 version.


Note! For EPiServer CMS 5, the only appSetting you might want to configure is the EPsBvn404HandlerPage to point to your own 404 page. The module is enabled by default and should work out of the box as long as you have a CustomRedirects.config file in your site root directory. The CustomRedirects.config can be put in a VPP, but if the VPP is not a VirtualPathNativeProvider the contents of the file will be cached until the site is restarted (and not just until the file is changed.)

    <!-- BEGIN 404 handler settings -->

        <!-- Where to look for custom redirects. Default value is: ~/CustomRedirects.xml -->
        <add key="EPsBvn404HandlerRedirectsXmlFile" value="~/CustomRedirects.config" />

        <!-- The 404 handler page. This is used by the http module when it redirects.
             Don't forget to set the 404 path in IIS to the same value in order to
             catch all 404 errors.
             Default value: "~/bvn/filenotfound/notfound.aspx"
        <add key="EPsBvn404HandlerPage" value="~/bvn/filenotfound/notfound.aspx" />

        <!-- Off, On, RemoteOnly
             Default value CMS 5: On
             Default value CMS 4: Off
        <add key="EPsBvn404HandlerMode" value="On" />

        <!-- If you have a backend webserver with the old site running, change
        this value with the backend server, like www2.mysite.com. The error
        handler will then try to find the requested page there.
        Default value: ""
        <add key="EPsBvn404HandlerBackendRootUrl" value="" />

    <!-- END 404 and Error handler settings -->

IIS 5/6 Settings

Add the following settings to web.config

      <add name="Bvn404Handler" type="BVNetwork.FileNotFound.Handler.CustomFileNotFoundHandler, BVNetwork.EPi404" />

Change the custom 404 error.

  • Open IIS Manager, right click your site, select Properties
  • Select the Custom Errors tab
  • Find the 404 entry in the list, change the following settings:
    • Message type: Url
    • Url: /bvn/filenotfound/notfound.aspx
  • Select the Home Directory tab
  • Click the Configuration button
  • If the .aspx extension is not in the "Application extensions" list, add it it with the following settings:
    No image "aspx.png" attached to 404Handler/DocCms5
    If the extension is already present, make sure it has the same settings as above.

IIS 7 / 7.5

Make sure you have the following configuration in your web.config file:

        <modules runAllManagedModulesForAllRequests="true">
            <add name="BVNetwork.EPi404"
                 type="BVNetwork.FileNotFound.Handler.CustomFileNotFoundHandler, BVNetwork.EPi404" />
        <httpErrors errorMode="Custom">
            <remove statusCode="404"
                    subStatusCode="-1" />
            <error statusCode="404"
                   responseMode="ExecuteURL" />

Make sure that "Error Pages" has been unlocked (Delegation set to Read/Write). You can edit this by selecting Feature Delegation in the iis root.

No image "featureDelegation.png" attached to 404Handler/DocCms5


  • For EPiServer CMS 5
    • EPiServer CMS 5 R2 SP1 or newer
    • Visual Studio 2008 to compile the code
    • Unleash-It to use the post-build event for deployment (not a requirement)
  • For EPiServer CMS 4
    • EPiServer CMS 4.50 or newer
    • Visual Studio 2005 to compile the code
    • Unleash-It to use the post-build event for deployment


As all code on EPiCode, use the ticket system or chat channel for support, and as always - use at your own risk.

Tickets for this component:

Change custom redirect file to use another extension to hide it from browsing
Allow wildcards in custom redirects
404 handler should not trigger on images
Use the SMTP settings in the correct way
Need httpmodule to handle exceptions
Interference with EPsErrorHandling?
Translation in Swedish
Missing httpModules section in documentation
Make the redirect list editable for an administrator
Redirects does not work on IIS 6
Redirects also affects EpiServer virtual admin interface
The module returns status code 302
Module ignoring querystrings when translating
Custom redirects without wildcard
Global exception logged after 404Handler redirects
Default language always shown
404 handler and globalization
302 Always Follows 301?
Show 404 enabled / disabled in gadget in dashboard
404 should not be activated in edit mode for missing plugins
New version?
after installation through the deployment center I get an error
Error after installation of 404Handler
Add count for 404 hits when url are redirects custom redirects
404Handler works very well on local IIS, but it does not work on a remote IIS Server
Delete suggestions in the 404 handler
issue with redirect
overwriting existing redirect on enterprise
404 handler for CMS 6.0 (and NOT 6.2)
How to specify redirect URLs for different domains?
Add suggestions filters
If we add a trailing /, it gets redirected wrongly
custom handler not working together with the redirects
404 suggestions for pages ending in /null
Norwegian letters in url
Suggestions with /null at the end of a valid URL>
Should the BVNetwork.FileNotFound.Redirects.RedirectsXmlParser constructor log an error if the Custom redirects file does not exist
Restricting Custom Redirects Manager gadget to certain roles
Gadget disappears from Dashboard
Get this error
Question: Delete all suggestions from database?
Move IgnoredResourceExtensions to web.config?
After installing NuGet package, references not added to 404Handler DLLs
Trackhandler issue
Delete suggestions but not custom redirects : Episerver 6
Gadget visible but not working
IndexOutOfRangeException in LogRequest
Images are not excluded
Installed BNV 404 Handler via Nuget and Redirect Gadget not loading
An error has occured in the dynamic data store: System.Threading.ThreadAbortException:
Request some details in order to extend the 404 redirect
Episerver 7.x : Warning during Initialization
EPiServer 8 Azure Web App - BVN 404 Custom redirect not working

Ask a question

Requires login.

Report a bug

Requires login.

Add a feature request

Requires login.