Debug Error 500 – IIS

1. ​Howto force error 500 to enable testing the error output and logging:

Navigate to site root or a page with ?someParam=<script> (note: this will be treated a a dangerour script and error 500 thrown).

2. MVC Web.config

<httpErrors errorMode=”Custom” existingResponse=”Auto”>
      <remove statusCode=”404″ />
      <error statusCode=”404″ path=”/404.html” responseMode=”ExecuteURL” />
      <remove statusCode=”500″ />
      <error statusCode=”500″ path=”/500.html” responseMode=”ExecuteURL” />
    </httpErrors>

The params errorMode & existingResponse behave so:

Custom + Auto = Serves the detailed error YSOD page, useful for debugging.

Custom + Replace = Serves the page configured here 500.html (or the one setup in IIS if not set in config). Hides error details, not so useful for debug, potentially useful for production envs.

Can use DetailedLocalOnly instead of Custom for similar effect.

Note: Elmah fails to log error 500 for some reason. We might be able to make it work by redirecting to an Error action (or Error.aspx)

Refer: https://www.iis.net/configreference/system.webserver/httperrors​

Disclaimer: No warranties attached, please use own judgement and analysis.

Leave a Reply

Your email address will not be published. Required fields are marked *