Financial Year 2023 End Sale: Get upto 40% OFF on Job-oriented Training! Offer Ending in
D
H
M
S
Get Now
Browse Tutorials
Turn off Asp.net Custom Errors in Web.config

Turn off Asp.net Custom Errors in Web.config

26 Mar 2024
Intermediate
69.9K Views
6 min read

Turn off Asp.net Custom Errors in Web.config: An Overview

Custom error in web.config might have been a frustrating moment for you too when your ASP.NET site throws an error and you get a generic error page instead of useful information. Don't be afraid! You can fix this by turning off custom errors in the Web.config file. Just dive into the configuration file, find the common errors section, and set the mode to "Disabled". Problem solved! In this Tutorial, we will understand just how to do that with other related information like What are Custom Errors?, How to Disable Custom Errors with Example. Delve deep into core concepts of ASP.NET with our ASP.NET Certification Training.

Read More: Top 50 ASP.NET Core Interview Questions and Answers for 2024

What are Custom Errors?

Custom errors enable you to choose how specific errors are displayed to users. You can set up several error pages, redirect users to another page, or even totally hide the error message. This can help prevent users from seeing technical details they don't understand.

Reasons to Turn Off Custom Errors

There could be many reasons for which Turning off Custom Errors in web.config can be beneficial. Some of them are:
  1. Disabling custom errors lets the developers see a detailed error information which will include line numbers and stack traces which will help them to identify and fix issues more efficiently.
  2. It lets the developers to quickly identify and address errors and they do not require any other steps to see detailed error messages which will help in faster debugging and testing.
  3. It also helps in enhancing the security by preventing sensitive information about the application's infrastructure to be exposed.

Read More: How can you become an ASP.NET developer

Disabling Custom Errors

There are two ways to disable custom errors in ASP.NET:
  1. Web.config: You can edit the customErrors element in the web.config file.
  2. IIS Manager: IIS Manager allows you to set custom errors for your application.

1. Web.config Method

  • The customErrors element is located in <system.web> in the web.config section.
  • It has a mode attribute that specifies how errors are handled.
  • If you disable this property, you can disable custom errors and see actual error messages.
  • In Asp.net, there are three error modes to trace an error:
    1. Off Mode: This mode is responsible for displaying error messages on local and remote servers in case of an error.
    2. On Mode: This mode is responsible for displaying a custom error page with a message on local and remote servers in case of an error. By using this mode, we can show our own custom error messages page for specific errors on local and remote servers.
    3. RemoteOnly: This mode is responsible for displaying error messages on remote servers only in case of an error. By using this mode, we can show our own custom error messages page for specific errors on the remote server only.

Example

<system.web>
  <customErrors mode="Off" />
</system.web>

After making this change, save the web.config file and restart the application. If an error occurs, you'll see a detailed error message instead of a friendly error page.

Runtime Error

A runtime error is a problem in code that happens while it is running and causes it to crash.

Runtime Error

Compilation Error

When program code is invalid and cannot be converted into machine code, a compilation error occurs.

Compilation Error

2. IIS Manager Method

  1. Launch IIS Manager.
  2. In the tree view, select the website for which you wish to disable custom errors.
  3. Select "Properties" from the menu when you right-click on the webpage.
  4. Select the "ASP.NET" tab in the properties window.
  5. Select the "Edit Configuration" option.
  6. Select the "Custom Errors" tab in the configuration editor.
  7. Change the "Mode" setting to "Off".
  8. Click "Apply" and then "OK" to save your changes.

When you restart your application, the actual error messages will be displayed rather than the custom error pages.

Example:

<configuration>
    <system.web>
        <customErrors mode="Off" />
    </system.web>
</configuration>
Summary

This article explains how to disable custom error pages in ASP.NET so you can see actual error messages for debugging. There are two options: edit the web.config file and use IIS Manager. The article also explains the different error modes available. Consider enrolling in our ASP.NET Certification Course to get your hands on the best step by step guide for ASP.NET

FAQs

Q1. How to get rid of common IIS errors?

Click "Change setting". Click the Custom Errors tab. For Custom Error Mode, select Disabled. Or go to the folder that contains your application and open the website.

Q2. How do you deal with network configuration errors?

You can handle default errors and HTTP errors by adding a customErrors web section. configuration file. In the CustomErrors section, you can set the default page that users will be redirected to when an error occurs. It also allows you to specify individual pages for specific status code errors.

Q3. Where are ASP.NET errors logged?

There are error entries in the Windows Event Log (Event Viewer > Windows Logs > Application) .NET Runtime and Application Error. Once you have confirmed that the detected error is a process crash, you are ready to gather information to file a bug report.

Q4. What is a custom error in asp.net?

  • OFF: ASP.NET uses its default error page for both local and remote users when an error occurs.
  • ON: Custom error is enabled on local and remote clients.
  • REMOTE ONLY: The custom error page will be shown only to the remote user, the local user will get the embedded error page.

Q5. How do I turn off custom error in web config?

To turn off custom error in web.config:
  1. Open the desired web.config file.
  2. set the 'mode' attribute of the '<customErrors>' element to 'Off'.
  3. Save the changes and restart your ASP.NET application to apply the new settings.

Take our free aspnet skill challenge to evaluate your skill

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET CHALLENGE

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this