How To Disable Friendly Error Messages Using the web.config File

How To Disable Friendly Error Messages Using the web.config File

When your website encounters an error, your web server may not display the actual script error, but will instead show a message such as the one below:



You may also see:



Friendly error messages such as the ones above make it hard to determine which file and what code line is causing the error.

There is a simply trick you can use to turn of friendly error message, using the web.config file.

A. If your site already has web.config file, follow these steps below:

1. Login to your site FTP and download your web.config file. Usually this file is located at the root level.

2. Open your web.config using your preferred text editor.

If you choose to open using notepad, click File > Open then browse to the web.config file location. Choose All files ( *.* ) so that you can see the web.config file.



Click to open the web.config file


3. Now insert the following code below just before the last line </configuration> :

<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>

NOTE :
a. If your web.config already have <system.webServer> tag, example :

<system.webServer>
.............[your existing code]................
.............[your existing code]................
.............[your existing code]................
</system.webServer>


Then you don't need to insert the full code like on step 3 :

<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>


You will just need to insert the <httpErrors errorMode="Detailed" />   inside the <system.webServer> </system.webServer> tag.

For example :

<system.webServer>
.............[your existing code]................
.............[your existing code]................
.............[your existing code]................
<httpErrors errorMode="Detailed" />
</system.webServer>

b. If your web.config already have <httpErrors> tag, then you don't need to insert another line for :

<httpErrors errorMode="Detailed" />

This will cause error to your site as they will be 2 tag of <httpErrors>

What you need to do is to replace your <httpErrors> with :

<httpErrors errorMode="Detailed" />


4. Save the file and upload to your FTP again ensuring you backup your existing web.config file.

B. If your site does not have web.config file, please follow these steps below:

1. Open notepad or text editor, create new file called web.config and paste the below code into it:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>

2. Save the file and upload to your site via FTP.


Times Viewed:
3866
Added By:
Wilson Keneshiro
Date Created:
8/2/2014
Last Updated:
4/26/2017