Loading...

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 for EPiServer 7

Important!

This library contains a custom 404 handler for your EPiServer 7 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. The module also includes a Custom Redirect Gadget (for EPiServer Online Center) for editors to add redirects. The handler also logs all 404 errors on your site. These errors get presented as redirect suggestions in the gadget, so that editors of the site can easily see which 404 errors that should be handled. Logged errors includes referrers, so that you are able to see where the error originated.

Redirects view:
Redirects view


Suggestions view:
The suggestions view


Administer view:
The administer view

Features

  • Custom 404 FileNotFound page to replace the built-in error page
  • Logging of all 404 errors. Logging is buffered, and comes with a configurable threshold value to avoid spam.
  • A custom redirect gadget so that editors can add and maintain redirects, and see redirect suggestions based on the logged errors.
  • An admin plugin that shows all the CustomRedirects defined

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.

Screenshots

See what the 404 page can look like

Download

down.gif Download Now

Changing the "notfound" page

After installing package you will find the 404notfound.aspx on the root of your site. You can, and should, change the 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.

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.

Configuration

Note! Below is an overview of the module configuration for EPiServer 7 CMS running on IIS7. The module is enabled by default and should work out of the box, however you need to use the gadget to add the redirects.

<configuration>
    ...
    <configSections>
        <section name="bvn404Handler"
                         type="BVNetwork.FileNotFound.Configuration.Bvn404HandlerConfiguration, BVNetwork.EPi404"/>
    </configSections>
  
    <bvn404Handler handlerMode="On"
                   fileNotFoundPage="/404notfound.aspx">
        <providers>
            <!--
                Register your own handler that will be given a chance to
                rewrite the url. The type must implement INotFoundHandler
                <add name="NameOfHandler" type="Your.Handler.Here" />
             -->
        </providers>
    </bvn404Handler>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            ...
            <add name="BVNetwork.EPi404"
                 type="BVNetwork.FileNotFound.Handler.CustomFileNotFoundHandler, BVNetwork.EPi404" />
        </modules>
        ...
        <httpErrors errorMode="Custom">
            <remove statusCode="404"
                    subStatusCode="-1" />
            <error statusCode="404"
                   prefixLanguageFilePath=""
                   path="/404notfound.aspx"
                   responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
    <episerver.shell>
        <publicModules rootPath="~/modules/"               
            autoDiscovery="Minimal">           
                <add name="BVNetwork.FileNotFound.RedirectGadget">
                    <assemblies>
                         <add assembly="BVNetwork.FileNotFound.RedirectGadget" />
                    </assemblies>
                </add>
         </publicModules>
    </episerver.shell>   
</configuration>

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.

Adding screenshot of feature delegation

Logging

Logging is by default set with a buffering value of 30, which means that the actual logging will happen for every 30 errors. You can edit the bvn404Handler section in the web.config and set bufferSize ="0" in order to log the errors immediately. However, it is recommended to not have the buffer set to 0, because if you do, then you be vulerable to spam and massive logging to your database. You can control how much you would like to log by specifying a threshold value. This value determines how frequent 404 errors are allowed to be logged. By default this value is set to 5. Examples on how this works:

  • Example 1:
    Case: 100 errors in 5 seconds -
    (diff = seconds between first logged request and the last logged request in the buffer).
    bufferSize is 100, diff is 5 seconds, threshold is 10.
    100 / 5 = 20. Error frequency is higher than threshold value. Buffered requests will not get logged.

  • Example 2:
    Case: 100 errors in 15 seconds - bufferSize is 100, diff is 15 seconds, threshold is 10.
    100 / 15 = 6. Error frequency is within threshold value. Buffered requests will get logged.

  • Threshold = Average maximum allowed requests per second.
  • If the bufferSize is set to 0, the threshold value will be ignored, and every request will be logged immediately.
  • Turn off logging by specifying logging="Off" (default value is "On").

Web.config example:

    <bvn404Handler handlerMode="On" logging="On" bufferSize="30" threshold="5"
                   fileNotFoundPage="/404notfound.aspx" >
        <providers>
            <!--
                Register your own handler that will be given a chance to
                rewrite the url. The type must implement INotFoundHandler
                <add name="NameOfHandler" type="Your.Handler.Here" />
             -->
        </providers>
    </bvn404Handler>

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.

Requirements

  • EPiServer 7 CMS or newer
  • Visual Studio 2010 / 2012 to compile the code
  • Unleash-It to use the post-build event for deployment (not a requirement)

Support

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:

Status: assigned (1 match)

Ticket Summary Type Priority Created Modified
#202 Module ignoring querystrings when translating defect major 8 years 7 years

Status: new (23 matches)

Ticket Summary Type Priority Created Modified
#364 EPiServer 8 Azure Web App - BVN 404 Custom redirect not working question critical 2 years 2 years
#363 Episerver 7.x : Warning during Initialization enhancement minor 2 years 2 years
#362 Request some details in order to extend the 404 redirect question major 2 years 2 years
#361 An error has occured in the dynamic data store: System.Threading.ThreadAbortException: question critical 3 years 3 years
#359 Installed BNV 404 Handler via Nuget and Redirect Gadget not loading defect major 3 years 3 years
#357 Images are not excluded question minor 3 years 3 years
#356 IndexOutOfRangeException in LogRequest defect major 4 years 2 years
#355 Gadget visible but not working defect major 4 years 4 years
#354 Delete suggestions but not custom redirects : Episerver 6 question major 4 years 4 years
#353 Trackhandler issue question major 4 years 4 years
#352 After installing NuGet package, references not added to 404Handler DLLs defect trivial 4 years 4 years
#351 Move IgnoredResourceExtensions to web.config? enhancement minor 4 years 4 years
#349 Get this error question critical 4 years 4 years
#346 Gadget disappears from Dashboard defect major 4 years 4 years
#345 Restricting Custom Redirects Manager gadget to certain roles question major 4 years 4 years
#333 Should the BVNetwork.FileNotFound.Redirects.RedirectsXmlParser constructor log an error if the Custom redirects file does not exist enhancement trivial 5 years 5 years
#320 If we add a trailing /, it gets redirected wrongly defect critical 5 years 5 years
#319 Add suggestions filters enhancement minor 5 years 5 years
#303 issue with redirect defect major 6 years 6 years
#285 Add count for 404 hits when url are redirects custom redirects enhancement minor 6 years 6 years
#279 404 should not be activated in edit mode for missing plugins enhancement trivial 6 years 6 years
#278 Show 404 enabled / disabled in gadget in dashboard enhancement minor 6 years 6 years
#247 Custom redirects without wildcard question minor 6 years 6 years

Status: closed (31 matches)

Ticket Summary Type Resolution Priority Created Modified
#350 Question: Delete all suggestions from database? question fixed major 4 years 4 years
#327 Suggestions with /null at the end of a valid URL> defect fixed critical 5 years 4 years
#324 Norwegian letters in url defect fixed major 5 years 5 years
#323 404 suggestions for pages ending in /null question duplicate minor 5 years 5 years
#322 custom handler not working together with the redirects defect fixed critical 5 years 5 years
#314 How to specify redirect URLs for different domains? question fixed major 5 years 5 years
#311 404 handler for CMS 6.0 (and NOT 6.2) question fixed minor 5 years 5 years
#306 overwriting existing redirect on enterprise defect fixed minor 5 years 5 years
#302 Delete suggestions in the 404 handler enhancement fixed minor 6 years 5 years
#296 404Handler works very well on local IIS, but it does not work on a remote IIS Server question fixed major 6 years 5 years
#284 Error after installation of 404Handler defect wontfix blocker 6 years 6 years
#283 after installation through the deployment center I get an error question fixed blocker 6 years 6 years
#280 New version? question fixed major 6 years 6 years
#277 302 Always Follows 301? question invalid major 6 years 6 years
#275 404 handler and globalization enhancement fixed minor 6 years 5 years
#273 Default language always shown defect wontfix major 6 years 6 years
#248 Global exception logged after 404Handler redirects question fixed minor 6 years 6 years
#203 Mirroring? question fixed major 8 years 8 years
#198 The module returns status code 302 defect fixed major 8 years 8 years
#165 Redirects also affects EpiServer virtual admin interface defect worksforme major 8 years 7 years
#128 Redirects does not work on IIS 6 defect fixed major 9 years 8 years
#43 CMS 5 enhancement fixed major 10 years 9 years
#29 Make the redirect list editable for an administrator enhancement fixed major 11 years 6 years
#28 Missing httpModules section in documentation defect fixed minor 11 years 11 years
#27 Translation in Swedish enhancement fixed minor 11 years 11 years
#16 Interference with EPsErrorHandling? defect fixed trivial 12 years 11 years
#14 Need httpmodule to handle exceptions enhancement fixed major 12 years 12 years
#7 Use the SMTP settings in the correct way defect fixed critical 12 years 9 years
#3 404 handler should not trigger on images defect fixed critical 12 years 9 years
#2 Allow wildcards in custom redirects defect fixed major 12 years 9 years
#1 Change custom redirect file to use another extension to hide it from browsing enhancement fixed major 12 years 10 years

Ask a question

Requires login.


Report a bug

Requires login.


Add a feature request

Requires login.


Attachments