18 September 2010

ASP.NET custom error not shown in Azure

If you’re using a custom error handler in an ASP.NET Azure web role, for example, to return a branded error page you may find the custom page isn’t surfaced too the browser and instead you receive a standard IIS error.

When your handler is setting the correct response status, relevant to the type of error e.g. 404, 500 etc, the default web role configuration means the error page content you supply will not be passed on. This is complicated by the DevFabric not using the same configuration i.e. your custom error page will appear as expected when you’re testing in DevFabric.

The configuration setting requiring tweaking is in the system.webServer section; setting httpErrors’ existingResponse attribute to “PassThrough” will ensure that, if any content is supplied with the ASP.NET error response, it is returned to the browser.

    <httpErrors existingResponse="PassThrough"/>