views:

38

answers:

1

I have ASP.NET set up to use the CustomErrors functionality:

<customErrors mode="On" defaultRedirect="~/ErrorPages/500.aspx" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="~/ErrorPages/404.aspx" />
    <error statusCode="500" redirect="~/ErrorPages/500.aspx" />
</customErrors>

Everything works nice, and the relevant error pages are shown when appropriate.

Except in the following two cases:

1) When there is an exception thrown in global.asax:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        throw new ApplicationException("Exception in Application_Start()");
    }
}

2) When there is a syntax error in web.config

In both cases, I don't see my pretty 500.aspx page. Instead, I see the standard ASP.NET yellow screen of death, with the following message:

Server Error in '/MvcErrorHandling' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.

How can I get ASP.NET or IIS to show a custom error page (a pretty one, instead of the YSOD) in the above two scenarios?

Thanks in advance for any input :)

A: 

The problem is that those specific errors are happening before ASP.NET can load things up, and your "500 internal server error" page is an .aspx page that requires ASP.NET to load.

The simplest option would be to make your 500 page an HTML page, but that would mean you can't do simple error logging, etc from there.

This may still not help the web.config scenario as if IIS can't process the web.config, there's no guarantee that it would read your error section.

Another option would be to tell IIS to serve a static html page on 500 errors.

Finally you could try catching errors in the Application_Error event in the web.config - this would at least allow you to process the error, even the page you try and display can't load up.

Zhaph - Ben Duguid