This post is out of date.

EPiServer 7 : Installing BVN.404Handler for an MVC Project

Install The Module

First, install the package 'BVN.404.Hamdler' via Nuget from the EPiServer Nuget feed: Next, download the extension and add in BVN.404Handler.MvcContrib plug-in by Mark Everard here.

Add/check the following is in your web.config 'configSections' section

<section name="bvn404Handler" type="BVNetwork.FileNotFound.Configuration.Bvn404HandlerConfiguration, BVNetwork.EPi404" />

Change the 'fileNotFoundPage' property in the 'bvn404Handler' section

By default, the BVN plug-in assumes you are using web forms rather than MVC so you will need to change the fileNotFoundPage attribute to point to the page you will create in EPiServer(You can override it with the snippet below BUT remember you need to create an EPiPage called page-not-found)

  <bvn404Handler handlerMode="On" fileNotFoundPage="/page-not-found/">
              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" />

Add/Check BVN has been registered in the modules section

To look like this:

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

Update/Add your httpErrors section

To look like this:

    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/en/page-not-found/" responseMode="ExecuteURL" />

Create The Views, Controllers, View Models andPageType Definition to be able to create the page within EPiServer

I won't go over step-by-step how to create each of these elements as it will be different based on your project.  You will need to create all the same basics you would for a normal page.

Create Your Page In EPiServer

After you have done all the tedious configuration stuff you will need to create your Error page in EPiServer. When a 404 is encountered, the plug-in will re-direct the user to your EPiServer page.  If that page doesn't exisit within EPiSever, nothing will be displayed when an error occurs. Creating your error page involves the same process as an other page except there's one difference in the controller.  You will need to add the [NotFoundPage] attribute to the class:

    public class _404Controller :  BasePageController<_404Page>
        public ActionResult Index(_404Page currentPage)
            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode = 404;

            var viewModel = new _404ViewModel(currentPage);
            return View("Index", viewModel);

Log into EPiServer and create the page!

In Episerver, create the page using your 404 page type (or whatever you have called or named it) /page-not-found/ (or whatever you have defined the name to be in the web.config). The URL matches the value you entered in the fileNotFoundPage section in the BVN404Handker section of your web.config.

Test It out

After you create and publish your page you should be able to test it out.  First open your site and make sure you can navigate to your error page normally. If you can't you may have to repeat some of the steps above.  When you can browse to the page normally, it's time to add in an invalid URL. This should also take your page cannot be found page. To check the re-direct part of the module works as expected, log into EPiServer and on the Dashboard tab if you click on new Gadget you should be able to see the custom redirect manager: Screenshot_1

Issues I Encountered

After using the BVN.404Handler module it broke my deployment centre. Whenever I tried to create a new sample site all I would get on page load was a 505 error.  To fix the issue after you have installed the site, in the IIS entry for the website, go to modules and remove the BVNNetwork.EPi404 entry. Your newly created site should now load :) Here's my working code sample... enjoy :) DOWNLOAD HERE

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top