Turn off Asp.net Custom Errors in Web.config

Turn off Asp.net Custom Errors in Web.config

07 Jun 2024
Intermediate
78.6K 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

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.

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.

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.

  • 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.

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.
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan, Founder and CEO of ScholarHat by DotNetTricks, is a renowned expert in System Design, Software Architecture, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development. His skill set extends into emerging fields like Data Science, Python, Azure AI/ML, and Generative AI, making him a well-rounded expert who bridges traditional development frameworks with cutting-edge advancements. Recognized as a Microsoft Most Valuable Professional (MVP) for an impressive 9 consecutive years (2016–2024), he has consistently demonstrated excellence in delivering impactful solutions and inspiring learners.

Shailendra’s unique, hands-on training programs and bestselling books have empowered thousands of professionals to excel in their careers and crack tough interviews. A visionary leader, he continues to revolutionize technology education with his innovative approach.
Accept cookies & close this