Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Mckibbin 14 posts 106 karma points
    Feb 27, 2020 @ 17:13
    Daniel Mckibbin
    0

    Render custom errors when database cannot connect

    So I'm currently trying to get my custom errors to work but when doing so I get the following error:

    Server Error in '/' Application.
    Runtime Error
    Description: 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.
    

    In the event viewer, the only exception happening is the standard database connection error exception but I need to show a custom error page when this happens (even if it's a static html page without using a controller).

    This is the custom errors tag in web.config under < system.web >

    <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error">
      <error statusCode="400" redirect="~/Error" />
      <error statusCode="404" redirect="~/Error/NotFound"  />
      <error statusCode="500" redirect="~/Error" />
    </customErrors>
    

    Error controller:

    using System.Web.Mvc;
    
    namespace Logic.Controllers
    {
        public class ErrorController : Controller
        {
            public ViewResult Index()
            {
                return View("Error");
            }
            public ViewResult NotFound()
            {
                return View("NotFound");
            }
        }
    }
    
  • Magnus Eriksson 122 posts 362 karma points
    Feb 28, 2020 @ 09:35
    Magnus Eriksson
    0

    I have this under <system.webServer> where the key part I believe is existingResponse="Replace"

      <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
          <remove statusCode="404" subStatusCode="-1" />
          <remove statusCode="500" subStatusCode="-1" />
          <error statusCode="404" path="/404" responseMode="ExecuteURL" />
          <error statusCode="500" path="/500error.html" responseMode="File" />
        </httpErrors>
    

    Regards, Magnus

  • Daniel Mckibbin 14 posts 106 karma points
    Mar 04, 2020 @ 09:21
    Daniel Mckibbin
    1

    I had used the httpErrors object under system.webServer previously, the responseMode="File" was the only difference which has successfully redirected it to my HTML file, however, that then gives me the following message "The page cannot be displayed because an internal server error has occurred.".

    I am just using a default HTML template as the page, so nothing that could be causing a further error, so I believe the database not connecting is preventing the static error page from displaying:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
    </body>
    </html>
    
Please Sign in or register to post replies

Write your reply to:

Draft