Why is my custom 404 handler always timing out?

  • Page Owner: Not Set
  • Last Reviewed: 2018-12-14

I have an Episerver site w/ a custom 404 handler, but it's sloooooooow. Why?

My web.config:

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

My Controller:

public class NotFoundPageController : BasePageController<NotFoundPage>
{
    public override ActionResult Index(NotFoundPage currentPage)
    {
        if (!PageEditing.PageIsInEditMode)
        {
            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode = 404;
        }

        var viewModel = PageViewModel.Create(currentPage);
        return View("~/Views/CollegeData/Pages/TextPage.cshtml", viewModel);
    }
}

What gives?


Answer

There's something about Episerver's Global Error handling that causes this problem. It appears to basically freeze the entire server for several minutes why it tries to process the 404 (or any other) error. The solution is to turn off Episerver's global error handling:

<applicationSettings globalErrorHandling="Off" ... />