Where and how to define <customErrors mode=”on”> for my asp.net MVC 3 web application

john Gu picture john Gu · Feb 15, 2012 · Viewed 52.7k times · Source

I want to set the custome error to be true to prevent users from viewing detailed info about my application. But I cannot find where I should write this <customErrors mode="on">; should it be in the web.config or in the web, debug.config or else where?

BR

Answer

Soul_Master picture Soul_Master · Nov 4, 2012

From my experience, we should turn custom error to On in release mode and turn it off in debug. To automatically do this, we can use web.config transformation like the following example.

Web.Debug.config

This setting will allow web server to display ASP.NET yellow page that contain useful error information.

<customErrors mode="Off" xdt:Transform="Replace" />

Web.Release.config

In the other hand, we don't want user to know technical error. We should use custom error page instead of ASP.NET yellow page.

<customErrors mode="On" xdt:Transform="Replace" />