title: Runtime Error: An exception occurred while executing the custom error page
body: <p>I am trying to set up custom errors using IIS for a .net framework application (built using Visual Studio 2015 if that's relevant.)  Our server is a windows server 2012 R2. I have viewed other stack overflow solutions to this issue but none have resolved it. I have custom errors set to on in my web config and in the server managers feature settings. The path to the custom error page (is a static html page) is set in the server manager for all error status codes. Some previous stacks suggested disabling python so I tried that, but it did not resolve anything. My web config looks like:</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;!--other web config--&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/&gt;
    &lt;/configSections&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0"/&gt;
      &lt;add key="webpages:Enabled" value="false"/&gt;
      &lt;add key="ClientValidationEnabled" value="true"/&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true"/&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;httpRuntime targetFramework="4.5"/&gt;
      &lt;customErrors defaultRedirect="/Views/Home/customError.cshtml" mode="On"/&gt;
      &lt;compilation debug="true"/&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;!--&lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
        &lt;remove statusCode="500" subStatusCode="-1" /&gt;
        &lt;error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/Views/Home/customError.cshtml" /&gt;
      &lt;/httpErrors&gt;--&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;connectionStrings&gt;
      &lt;add name="Entities" connectionString="***" providerName="System.Data.EntityClient"/&gt;
    &lt;/connectionStrings&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="v12.0"/&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I didn't see any duplicate static content in the web config. I added all the iis error page redirects directly in the server manager for the application.  </p>
  
  <p>When I run the application locally and try to trigger a 404 error, I get the runtime error: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated. 
  When I run it via the server(also trying to trigger a 404 error), it loads to the previous page. </p>
  
  <p>I am unsure how to go about resolving this. Any insight would be awesome! Thank you!</p>
  
  <p>Relevant part of the controller: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.Entity;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Net;
  using System.Net.Mail;
  using BE.Models;
  using BE.ViewModels;
  
  namespace BE.Controllers
  {
  
      public class HomeController : Controller
      {
  
          private Entities db = new Entities();
  
          // Uri Route: "~/Home"
          // View Route: "/Views/Home/Index.cshtml"
          public ActionResult Index()
          {
              return View();
          }
  
  
          // Route: "~/Home/customError"
          // View Route: "/Views/Home/customError.cshtml"
          public ActionResult customError()
          {
              return View();
          }
  
          public ActionResult About()
          {
              return View();
          }
  
  
          public ActionResult Contact()
          {
              return View();
          }
  
  
  
          public ActionResult Resources()
          {
              return View();
          }
  
      }
  }
  </code></pre>
  
  <p>I also modified the global.asax.cs to look like:</p>
  
  <pre><code>namespace BE
  {
      public class MvcApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
          }
          RouteTable.Routes.MapRoute(
          "Default",
          "{controller}/{action}/{id}",
           new { 
               controller = "Home", 
               action = "Index", 
               id = UrlParameter.Optional
          }
      );
      };
  };
  </code></pre>
  
  <p>However, this gives me build errors.</p>