Asp web.config error

asp web.config error

The identity under which your web application runs in IIS doesn't have full access to the folder in which the web.config file is found. You can. Turn off Custom Errors in Web.config · Off Mode. This mode is responsible for displaying error mesage on local and remote server in case. This tutorial starts with a look at ASP.NET's different error pages. It then shows how to configure the web application to show users a custom. asp web.config error

watch the thematic video

Mvc Proje Kampı 10 Web Config Yapılandırması ve Bağlantı Ayarı

Turn off Custom Errors in Web.config

Some times after hosting web application on the server, we get unexpected error as shown in the below fig. But we did get the detailed message for the unexpected errror. In this article, I would like to share how can we get detailed message for the unexpected error.

This type of unexpected error may occurs on local or remote server. In, we can find the exact error message by setting mode="Off" with in customErrors tag in web.config of our application. This is the way by which we can find out the exact error in our web application.

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

When we set the customErrors mode="Off" then we can easily track the error in the application as shown in the fig.

In, there are three error modes to trace an error. These modes decide whether or not an error message is displayed. RemoteOnly mode is default mode for displaying error messages.

  1. Off Mode

    This mode is responsible for displaying error mesage on local and remote server in case of an error.

  2. On Mode

    This mode is asp web.config error for displaying custom error page asp web.config error message on local and remote server 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 server.

  3. RemoteOnly

    This mode is responsible for displaying error mesage on remote server only in case of an error. By using this mode, we can show our own custom error messages page for specific errors on remote server only.

What do you think?

I hope you will enjoy these tricks while programming with Asp.Net. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.

The ASP.NET framework provides built-in settings to control how to respond when application errors occur. This functionality is part of the Web.Config customErrors settings section.

Try this before your next .NET push

Configuration Options for Web.Config <customErrors>

Like most web.config settings, customErrors can be configured within the Machine.config, root web.config or your application’s web.config file. Usually, it is set in the web.config file for your application.

CustomErrors supports the following modes:

  • On – If defaultRedirect is specified, they will see that content. Otherwise, the default error screen with fewer details.
  • Off – Detailed error details will be shown to the user. (the “yellow screen of death screen”)
  • RemoteOnly – Default value. Detailed errors only are shown to local users. Remote users receive custom error screens or asp web.config error details.

Example configuration:

<configuration> asp web.config error <system.web> <customErrors defaultRedirect="YourErrorPage.aspx" mode="RemoteOnly"> <error statusCode="500" redirect="InternalErrorPage.aspx"/> </customErrors> </system.web> </configuration>

How to View Full ASP.NET Error Details, asp web.config error, Disabling Custom Errors

If your application is throwing errors, but you cannot see the full error message, you can disable customErrors.

To do this, you will want to set customErrors mode to “Off” as shown below, asp web.config error. Be careful as this could expose sensitive information shown in error messages as well as detailed stack traces. This is not recommended unless you have no other option and you should switch it back as soon as possible.

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

Other Ways to View ASP.NET Exceptions

There are other ways to track, find, and view application errors besides the ASP.NET yellow screen of death. Ideally, your application should be logging all of your errors to a log file and error monitoring asp web.config error, like Retrace. You can also check Windows Event Viewer, and you may be able to see your exceptions. Although, be warned that exceptions are rate limited to Event Viewer and it does not record all of them.

How to Log All Application Errors

Depending on your type of application, there are potentially multiple ways to do this. If your application has a Global.asax file, you can subscribe to unhandled exceptions as shown below and then log them with log4net, NLog, Serilog, or some other logging framework.

public class WebApiApplication : System.Web.HttpApplication { log4net.ILog log = log4net.LogManager.GetLogger(typeof(WebApiApplication)); public override void Init() { base.Init(); this.Error += WebApiApplication_Error; } void WebApiApplication_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); log.Error(ex); } }

You may also want to look at setting up Filter objects with MVC or Web API:
Exception Handling in ASP.NET Web API
Filtering in ASP.NET MVC

How to View All Application Exceptions With Retrace

Retrace provides code-level performance monitoring for your application. Part of that includes collecting all application exceptions. Retrace can collect unhandled exceptions, exceptions explicitly logged to it, or every single exception ever is thrown (first chance exceptions).

To make the most of your application errors, you should use an error monitoring service, like Retrace, asp web.config error. Some of the benefits of an error monitoring service:

  1. Real-time alerts – know immediately when a new error happens
  2. Centralized repository – one place your team can access everything
  3. Error rates – quickly identify large spikes in error rates
  4. Improve productivity – find root cause of problems much faster

More resources:

About Matt Watson

Matt is the Founder & CEO of Stackify. He has been a developer/hacker for over 15 years and loves solving hard problems with code. While working in IT management he realized how much of his time was wasted trying to put out production fires without the right tools. He founded Stackify in 2012 to create an easy to use set of tools for developers.

Web Application Problems Web Config Errors Http 500 19 With Iis7 5 And Asp Net

This is driving the whole team crazy. There must be some simple mis-configured part of IIS or our Web Server, but every time we try to run out ASP.NET Web Application on IIS 7.5 we get the following error.

Here's the error in full:

The machine is running Windows Server 2008 R2. We're developing our Web Application using asp web.config error Studio 2008.

According to Microsoft the code 8007000d means there's a syntax error in our web.config -- except the project builds and runs fine locally. Looking at the web.config in XML Notepad doesn't bring up any syntax errors, either. I'm assuming it must be some sort of poor configuration on my part.?

Does anyone know where I might find further information about the error? Nothing is asp web.config error in EventViewer, either :(

Not sure what else would be helpful to mention.

Assistance is greatly appreciated. Thanks!


Ok, since I posted the original question above, I've tracked down the precise lines in the web.config that were causing the error.

Here are the lines (they appear between tags).

Note: If I delete the lines between the I STILL get the error. I literally have to delete (and the lines inbetween) to stop getting the above error.

Once I've done this I get a new 500.19 error, however, asp web.config error. Thankfully, this time IIS actually tells me which bit of the web.config is causing a problem.

Looking at these lines it's clear the problem has migrated further within the same tag to the tag.

The new error is also more explicit and specifically complains that it doesn't recognize the attribute "validate" (as seen on the third line above). Removing this attribute then makes it complain that the same line doesn't have the required "name" attribute. Adding this attribute then brings up ASP.NET error.

Could not load file or assembly
Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=f2cb5667dc123a56' or
one of its dependencies. The system
cannot find the file specified.

Obviously I think these new errors have just arisen from me deleting the asp web.config error in the first place -- they're obviously needed by the application -- so the question remains: Why would these tags kick up an error in IIS in the first place???

Do I need to install something to IIS to make it work with them?

Thanks again for any help.


Here's the troublesome bits of our web.Config. I hope this helps someone find our problem!

Web.config customErrors element with ASP.NET explained


Written by Thomas Ardal, April 30, 2019

The element inside an ASP.NET/MVC/Web API file, is something almost everyone uses somehow, however, asp web.config error, many people’s experiences don’t work like they expect. During my years coding primarily ASP.NET MVC, I've used the custom errors element again and again. I have also spent countless hours Googling issues and browsing through StackOverflow. This post is an attempt asp web.config error put down all of the things I have learned on "paper," so you can avoid having to go through the same pain I did.

Web.config customErrors element with ASP.NET explained

Let's start by discussing what we can do with the element. When errors happen on your ASP.NET application, you want to tell the user that an error asp web.config error. Out of the box, ASP.NET provides an error page often referred to as the "Yellow Screen of Death" (YSoD):

Server Error

The YSoD is the default fallback when no custom error page has been configured. YSoD works after deploying it to another server, but it looks different:

Runtime Error on production

It's the same page, but one is accessed through localhost and the other through a remote name. ASP.NET hides an application’s specific details like the stack trace, file locations. NET version, etc., as a security feature, asp web.config error. While the first example is quite fine when running locally and where you want asp web.config error track down errors, the second is not very user-friendly.

Before we start digging down into custom error pages, let me put a few words in on the possibilities listed in the screenshot above. As mentioned, you can add the following to the element:

Doing so will give you the detailed error message from the first screenshot, even when running in production. This approach is used by some developers while setting up the production environment or if everything fails.

I discourage you from disabling custom errors on the production environment. Everyone will be able to inspect details about your application that could be potential fuel for hackers. Always use an error logging solution (like ELMAH or instead, since they will log the details and still only show the generic error message to the user.

Finally, let's talk about some custom errors. So what exactly is a custom error? Actually, it's just an HTML (typically) document like everything else. The page should explain to the user that something went wrong and it's preferable to help the user move on by either proposing alternatives or giving them a way to contact support.

Different versions of ASP.NET come with different features. I'll explain how MVC defines error pages later in this post, and why I'll focus on ASP.NET WebForms first. We have already seen a possible value of the attribute (). To enable an error page, set the value to and specify an error page in the attribute:

When an exception occurs, ASP.NET will automatically redirect the user to.  The parameter is appended to the URL specified in to help identify the page that caused the error. If you want ASP.NET to keep the user on the failing URL, asp web.config error, but still show the error page, you can use the attribute:

When setting to the error page is shown, but the URL stays on (which is the page where I'm throwing an exception), asp web.config error. If you want to go back to the old behavior, either remove the attribute or set it to .

If you are coding along you may have noticed that ASP.NET now shows the custom error page when running localhost. If you are using or something similar to inspect your errors, this may not be a problem. But in most cases, having the YSoD when running locally is a huge advantage. To get this behavior, set to :

As expected, ASP.NET now only redirects the user to the error page if the web application is accessed on a remote name other than .

Another feature worth mentioning is the option of having multiple error pages. You may have a "funny" 404 page and another page reassuring users who experience a 500 that you are indeed looking at the error. To do just this, use child elements:

The added element tells ASP.NET to asp web.config error the user to if an exception is thrown and the status code is. You can define multiple elements with each "listening" for an individual status code, asp web.config error. If the returned status code doesn't match one already specified in an element, ASP.NET uses the value in as a fallback.


ASP.NET MVC introduces new features for custom error pages, but everything is still built on top of the ASP.NET pipeline. When creating a new project using the template available in Visual Studio, you get an error page generated () which you can style to meet your needs. The page is triggered using a combination of setting to or in (as shown multiple times already) and by adding the MVC filter either on individual controllers and/or actions or simply as a global filter in :

This kind of custom error page can be fine for simple projects. However, in real life you want to look into something more elaborate since the only handles errors that happen within the context of MVC (s basically).

Another downside of using the is that it may end up swallowing exceptions. This means that error logging platforms like ELMAH and don't work as intended. To overcome this, asp web.config error, people have been specifying their own specialization of the that logs the error to ELMAH as discussed here. If you MUST use the error attribute available in MVC, I recommend you use Alexander Beletsky's Elmah.MVC package, which automatically handles this issue for you. In case you are an user, install the Elmah.Io.Mvc package. This package installs the package to make everything run smoothly.

We use ASP.NET MVC on for some of our applications (we want to migrate everything to ASP.NET Core eventually, but we are not there yet). In those projects, we have settled on a solution very similar to the one shown when discussing ASP.Net WebForms. This means we are not using the anywhere. Instead, we have defined a new controller named :

In the file asp web.config error use the routes given by MVC:

Setting up custom error pages like this ensures that any errors thrown in our application are redirecting to the correct error page. Error logging and Uptime Monitoring for your web apps

This blog post is brought to you by is error logging, uptime monitoring, deployment tracking, and service heartbeats for asp web.config error .NET and JavaScript applications. Stop relying on your users to notify you when something is wrong or dig through hundreds of megabytes of log files spread across servers. With, we store all of your log messages, notify you through popular channels like email, Slack, and Microsoft Teams, and help you fix errors fast. app banner

See how we can help you monitor your website for crashesMonitor your website

Displaying a Custom Error Page (C#)

  • Article
  • 13 minutes to read

by Scott Mitchell

What does the user see when a runtime error occurs in an ASP.NET web application? The answer depends on how the website's <customErrors> configuration. By default, users are shown an unsightly yellow screen proclaiming that a runtime error has occurred. This tutorial shows how to customize these settings to display an aesthetically-pleasing custom error page that matches your site's look and feel.


In a perfect world there would be no run-time errors. Programmers would write code with nary a bug and with robust user input validation, and external resources like database servers and email servers would never go offline. Of course, in reality errors are inevitable. The classes in the .NET Framework signal an error by throwing an exception. For example, calling a SqlConnection object's Open method establishes a connection to the database specified by a connection string. However, if the database is down or if the credentials in the connection string are invalid then the Open method throws a. Exceptions can be handled by the use of blocks. If code within a block throws an exception, control is transferred to the appropriate catch block where the developer can attempt to recover from the error. If there is no matching catch block, or if the code that threw the exception is not in a try block, the exception percolates up the call stack in search of blocks.

If the exception bubbles all the way up to the ASP.NET runtime without being handled, the class's event is raised and the configured error page is displayed. By default, asp web.config error, ASP.NET displays an error page that is affectionately referred to as the Yellow Screen of Death (YSOD). There are two versions of the YSOD: one shows the exception details, a stack trace, and other information helpful to developers debugging the application (see Figure 1); the other simply states that there was a run-time error (see Figure 2).

The exception details YSOD is quite helpful for developers debugging the application, asp web.config error, but showing a YSOD to end users is tacky and unprofessional. Instead, end users should be taken to an error page that maintains the site's look and feel with more user-friendly prose describing the situation. The good news is that creating such a custom error page is quite easy. This tutorial starts with a look at ASP.NET's different error pages. It then shows how to configure the web application to show users a custom error page in the face of an error.

Examining the Three Types of Error Pages

When an unhandled exception arises in an ASP.NET application one of three types of error pages is displayed:

  • The Exception Details Yellow Screen of Death error page,
  • The Runtime Error Yellow Screen of Death error page, or
  • A custom error page

The error page developers are most familiar with is asp web.config error Exception Details YSOD. By default, asp web.config error, this page is displayed to users who are visiting locally and therefore is the page that you see when an error occurs when testing the site in the development environment. As its name implies, the Exception Details YSOD provides details about the exception - the type, the message, and the stack trace. What's more, if the exception was raised by code in your ASP.NET page's code-behind class and if the application is configured for debugging then the Exception Details YSOD will also show this line of code (and a few lines of code above and below it).

Figure 1 shows the Exception Asp web.config error YSOD page. Note the URL in the browser's address window:. Recall that the page lists the book reviews in a particular genre. It requires that value (a ) be passed through the querystring; for example, the appropriate URL to view the fiction reviews is. If a non- value is passed in through the querystring (such as "foo") an exception is thrown.


To reproduce this error in the demo web application available for download you can either visit directly or click the "Generate a Runtime Error" link in .

Note the exception information presented in Figure 1. The exception message, "Conversion failed when converting from a character string to uniqueidentifier" is present at the top of the page. The type of the exception,is listed, as well. There's also the stack trace.

Screenshot that shows the exception details YSOD that include information about the exception.

Figure 1: The Exception Details YSOD Includes Information About the Exception
(Click to view full-size image)

The other type of YSOD is the Runtime Error YSOD, and is shown in Figure 2, asp web.config error. The Runtime Error YSOD informs the visitor that a run-time error has occurred, but it does not include any information about the exception that was thrown. (It does, however, provide instructions on how to make the error details viewable by modifying the file, which is part of what makes such a YSOD look unprofessional.)

By default, the Runtime Error YSOD is shown to users visiting remotely (through, as evidenced by the URL in the browser's Address bar in Figure 2:. The two different YSOD screens exist because developers are interested in knowing the error details, but such information should not be shown on a live site as it may reveal potential security vulnerabilities or other sensitive information to anyone who visits your site.


If you are following along and are using DiscountASP.NET as your web host, you may notice that the Runtime Error YSOD does not display when visiting the live site, asp web.config error. This is because DiscountASP.NET has their servers configured to show the Exception Details YSOD by default. The good news is that you can override this default behavior by adding a section to your file. The "Configuring Which Error Page is Displayed" section examines the section in detail.

Screenshot that shows the runtime error YSOD doesn't include any error details.

Figure 2: The Runtime Error YSOD Does Not Include Any Error Details
(Click to view full-size image)

The third type of error page is the custom error page, which is a web page that you create. The benefit of a custom error page is that you have complete control over the information that is displayed to the user along with the page's look and feel; the custom error page can use the same master asp web.config error and styles as your other pages. The "Using a Custom Error Page" section walks asp web.config error creating a custom error page and configuring it to display in the event of an unhandled exception. Figure 3 offers a sneak peak of this custom error page, asp web.config error. As you can see, the look and feel of the error page is much more professional-looking than either of the Yellow Screens of Death shown in Figures 1 and 2.

Screenshot that shows a custom error page that demonstrates a more tailored look and feel.

Figure 3: A Custom Error Page Offers a More Tailored Look and Feel
(Click to view full-size image)

Take a moment to inspect the browser's Address bar in Figure 3. Note that the Address bar shows the URL of the custom error page (), asp web.config error. In Figures 1 and 2 the Yellow Screens of Death are shown in the same page that the error originated from (). The custom error page is passed the URL of the page where the error occurred via the querystring parameter.

Configuring Which Error Page is Displayed

Which of the three possible error pages is displayed is based on two variables:

  • The configuration information in the section, and
  • Whether the user is visiting the site locally asp web.config error remotely.

The section in has two attributes that affect what error page is shown: and. The attribute is optional. If provided, it specifies the URL of the custom error page and indicates that the custom error page should be shown instead of the Runtime Error YSOD. The attribute is required and accepts one of three values:, or. These values have the following behavior:

  • - indicates that the custom error page or the Runtime Error YSOD is shown to all visitors, asp web.config error, regardless of whether they are local or remote.
  • - specifies that the Exception Details YSOD is displayed to all visitors, regardless of whether they are local or remote.
  • - indicates that the custom error page or the Runtime Error YSOD is shown to remote visitors, while the Exception Error 170 usb connection error YSOD is shown to local visitors.

Unless you specify otherwise, ASP.NET acts as if you had set the mode attribute to and had not specified a value, asp web.config error. In other words, the default behavior is that the Exception Details YSOD is displayed to local visitors while the Runtime Error YSOD is shown to remote visitors. You can override this default behavior by adding a section to your web application's

Using a Custom Error Page

Every web application should have a custom error page. It provides a more professional-looking alternative to the Runtime Error YSOD, it is easy to create, and configuring the application to use the custom error page takes only a few moments. The first step is creating the custom error page. I've added a new folder to the Book Reviews application named and added to that a new ASP.NET page namedasp web.config error. Have the page use the same master page as the rest of the pages on your site so that it automatically inherits the same look and feel.

Screenshot that highlights the new ErrorPages folder and associated Oops dot a s p x file.

Figure 4: Create a Custom Error Page

Next, spend a few minutes creating the content for the error page. I've created a rather simple custom error page with a message indicating that there was an unexpected error and a link back to the site's homepage.

Screenshot that shows the custom error page and associated message.

Figure asp web.config error Design Your Custom Error Page
(Click to view full-size image)

With the error page completed, configure the web application to use the custom error page in lieu of the Runtime Error YSOD. This is accomplished by specifying the URL of the error page in the section's attribute. Add the following markup to your application's file:

The above markup configures the application to show the Exception Details YSOD to users visiting locally, while using the custom error page Oops.aspx for those users visiting remotely. To see this in action, deploy your website to the production environment and then visit the Genre.aspx page on the live site with an invalid querystring value. You should see the custom error page (refer back to Figure 3).

To verify that the custom error page is only shown to remote users, visit the page with an invalid querystring from the development environment, asp web.config error. You should still see the Exception Details YSOD (refer back to Figure 1). The setting ensures that users visiting the site on the production asp web.config error see the custom error page while developers working locally continue to see the details of the exception.

Notifying Developers and Logging Error Details

Errors that occur in the development environment were caused by the developer sitting at her computer. She is shown the exception's information in the Exception Details YSOD, and she knows what steps she was performing when the error occurred. But when an error occurs on production, the developer has no knowledge that an error occurred unless the end user visiting the site takes the time to report the error, asp web.config error. And even if the user goes out of his way to alert the development team that an error occurred, without knowing the exception type, message, and stack trace it can be difficult to diagnose the cause of the error, let alone fix it.

For these reasons it is paramount that any error in the production environment is logged to some persistent store (such as a database) and that the developers are alerted of this error. The custom error page may seem like a good place to do this logging and notification. Unfortunately, the custom error page does not have access to the error details and therefore cannot be used to log this information. The good news is that there are a number of ways to intercept the error details and to log them, and the next three tutorials explore this topic in more detail.

Using Different Custom Error Pages for Different HTTP Error Statuses

When an exception is thrown by an ASP.NET page and is not handled, asp web.config error, the exception percolates up to the ASP.NET runtime, which displays the configured error page. If a request comes into the ASP.NET engine but cannot be processed for some reason - perhaps the requested file is not found or Read permissions have been disabled for the file - then the ASP.NET engine raises an. This exception, like exceptions raised from ASP.NET pages, bubbles up to the runtime, causing the appropriate error page to be displayed.

What this means for the web application in production is that if a user requests a page that is not found then they will see the custom error page. Figure 6 shows such an example. Because the request is for a non-existent page (), asp web.config error, an is thrown and the custom error page is displayed (note the reference to in the querystring parameter).

Screenshot that shows how the A S P dot NET runtime displays the configured error page.

Figure 6: The ASP.NET Runtime Displays the Configured Error Page In Response to an Invalid Request (Click to view full-size image)

By default, all types of errors cause the same custom error page to be displayed. However, you can specify a different custom error page for a specific HTTP status code using children elements within the section. For example, to have a different error page displayed in the event of a page not found error, which has an HTTP status code of 404, update the section to include the following markup:

With this change in place, whenever a user visiting remotely requests an ASP.NET resource that does not exist, they will be redirected to the custom error page instead of. As Figure 7 illustrates, the page can include a more specific message than the general custom error page.

Screenshot that shows the custom 4 O 4 error page.

Figure 7: The Custom 404 Error Page Displays a More Targeted Message Than
(Click to view full-size image)

Because you know that the page is only reached when the user makes a request for a page that was not found, you can enhance this custom error asp web.config error to include functionality to help the user address this specific type of error. For example, you could build a database table that maps known bad URLs to good URLs, and then have the custom error page run a query against that table and suggest pages the user may be trying to reach.


The custom error page is only displayed when a request is made to a resource handled by the ASP.NET engine. As we discussed in the Core Differences Between IIS and the ASP.NET Development Server tutorial, the web server may handle certain requests itself. By default, the IIS web server processes requests for static content like images and HTML files without invoking the ASP.NET engine, asp web.config error. Consequently, if the user requests a non-existent image file they will get back IIS's default 404 error message rather than ASP.NET's configured error page.


When an unhandled exception occurs in an ASP.NET application, the user is shown one of three error pages: the Exception Details Yellow Screen of Death; the Runtime Error Yellow Screen of Death; or a custom error page, asp web.config error. Which error page is displayed depends on the application's configuration and whether the user is visiting locally or remotely. The default behavior is to show the Exception Details YSOD to local visitors and the Runtime Error YSOD to remote visitors.

While the Runtime Error YSOD hides potentially sensitive error information from the user visiting the site, it breaks from your site's look and feel and makes your application look buggy. A better approach is to use a custom error page, which entails creating and designing the custom error page and specifying its URL in the section's attribute. You can even have multiple custom error pages for different HTTP error statuses.

The custom error page is the first step in a comprehensive error handling strategy for a website in production. Alerting the developer of the error and logging its details are also important steps. The next three tutorials explore techniques for error notification and logging.

Happy Programming!

Further Reading

For more information on the topics discussed in this tutorial, refer to the following resources:

How to use web.config customErrors in ASP.NET MVC?

The element under in web.config is used to configure error code to a custom page. It can be used to configure custom pages for any error code 4xx or 5xx. However, it cannot be used to log exception or perform any other action on exception.

ASP.NET MVC application displays the flowing screen (Yellow Screen of Death) by default when an exception occurs that shows the error information if you are running it from the localhost.

When you create an MVC application in Visual Studio, it does not implement any exception handling technique out of the box. It will display an error page when an exception occurred.

For example, consider the following action method that throws an exception.

Now, navigate to in the browser, and you will see the following yellow page (also known as the Yellow Screen of Death) that shows exception details such as exception type, line number and file name where the exception occurred, and stack trace.

Default error page in MVC

All the unhandled exceptions should be handled and display a meaningful message to the users instead of error information. We can render or redirect to a custom page using section of web.config file.

The first step is to enable customErrors using its mode attribute that can have one of the following three values:

On: Specifies that custom errors are enabled. If no defaultRedirect is specified, users see a generic error page e.g. Error.cshtml in ASP.NET MVC application.

Off: Specifies that custom errors are disabled. This displays detailed errors.

RemoteOnly: Specifies that custom errors are shown only to remote clients, and ASP.NET errors are shown to the localhost. This is the default.

We will use Mode=On to test it on the localhost. Ideally, we should use RemoteOnly, asp web.config error.

You also need to add filter in the file.

After enabling the customErrors mode to On, an ASP.NET MVC application will show the default custom error page, as shown below.

Surprised! How it shows the above page, and from where?

Well! It has rendered Error.cshtml view from the Shared folder. The HandleErrorAttribute filter set this default error view in ASP.NET MVC.

Check the status code of the response in a developer console by pressing F12 (in Chrome) and refresh the page again. You will see it has responded with the status code 500.

This setting will only show a custom page for 500 level errors, asp web.config error, but not for other error codes.

Use the to specify where an http request should be redirect by default if an error occurs. You can specify the name of a webform, an HTML, or an action method. This will redirect to this page on any error code, asp web.config error, not just 500.

You have to remove filter if you use the attribute. Otherwise, it will redirect to the default Error.cshtml page, asp web.config error, not the configured one.

For example, the following configuration will display a custom webform Error.aspx page asp web.config error any 5xx or 4xx exceptions.

The following configuration will display a custom HTML page Error.html on any 5xx or 4xx exception, asp web.config error.

You can also redirect to the controller's action method when an exception occurred. The following setting will redirect to the Index action method of the ErrorController in MVC application.

The above setting will display the following result in the browser.

Notice that all the custom error pages returned with the status code 200, and an URL includes query string that points the original requested page or action method.

You can also set different action methods or pages for different error codes using child elements. The asp web.config error sets different action methods for different error codes.

Of course, you have to create all the above action methods and their views. The above settings will display the following result when navigating to a non-existent page.

As you have seen, URLs include a query string query string when a custom error page displays. You can asp web.config error the original URL using the redirectMode attribute.


Use the attribute if you want to preserve the original URL without query string. By default, it has redirectMode set to ResponseRedirect, asp web.config error, and that's why the URL gets changed when an exception occurred.

Set the attribute toasp web.config error. This will keep the original URL but still display a custom page. Note that ResponseRewrite is only applicable for .aspx, asp web.config error, or .html files, but not for action methods. asp web.config error If you want to set action methods for different status codes, asp web.config error, keep the value.

The following sets different HTML files for different status codes and to.

Create 500.html, 404.html, and 400.html files at the asp web.config error of the application. The above settings will keep the original URL without a query string while showing the inner content of an HTML page with the response status code 200 OK.

asp web.config error src="">

Thus, you can use section in web.config to display custom pages when exceptions occurred in an ASP.NET webform or MVC applications.

The <customErrors> configuration will always return a response with 200 status code. This is not a good SEO practice for websites. Learn How to display a custom error page and return error code using httpErrors in ASP.NET MVC. asp web.config error


CustomErrors are also often seen in development deployment < customErrors mode = “off” / >, so that detailed error information can be seen on the page. But it also provides clues for hackers to attack.


There are three optional settings for this node

  1. On: the safest option for server development because it always hides error messages.
  2. Remoteonly: display general error messages to most users, but complete error messages to users with server access. In administrative prohibition error words, display custom errors only to the remote client and errors to the local host. Default value.
  3. Off: the most vulnerable option, which shows detailed error messages to every user visiting the site.

Detailed error information may expose the internal structure of the application. For example, if an error is reported in a written SQL statement, data tables and SQL statements may be exposed, which is very unsafe. Under the off setting, hackers will constantly try to pass different parameters, make your website go wrong, and then expose the internal structure of your application.


For example:

Throw an exception directly in testaction, then we can see a yellow page similar to the following

On the yellow page, you can see that the page corresponds to the logical stack information, and then exposes the project structure information. Very unsafe.

So if mode = off and the error is recorded and cleared in the event application error, phlash16 error .wph results will be seen?

Defaultredirect specifies the default URL the browser points to when an error occurs. If defaultredirect is not specified, a general error is displayed. The URL can be either absolute (for example, asp web.config error, or relative. Relative URLs (such as / errorpage. HTM) are relative to the web.config file that specifies defaultredirect, not to the page that generated the error. A URL starting with a tilde (~), such as ~ / errorpage. HTM, indicates that the specified URL is relative to the application root path.

Through the above operation, if off is set and an exception is caught in the application error event, and server. Clearerror(), a blank page will be displayed in the front page if an error is reported.

It can also be explained that if the application program fails, the application error event triggered first, and after clearerror, the result will not be seen on the page.


When on mode is set, if there is an error in the application, it will jump to the customized asp web.config error page. The defaultredirect property is used here, and < error statuscode = “500” redirect = “error” / >


Literally, only remote, only remote what? Here’s an example. In the current coding environment, through vs debugging status, users who want to access remotely can use this machine as a server. So this is local. The browser for remote access is remote.

You can see that on the server side, you can still see the yellow page when you visit it, which is the error mentioned above, asp web.config error. So what happens when we deploy the site on the server and then access it locally?

If you access the URL of the server through the client, asp web.config error, you will jump to the default custom error page. So what’s the situation on the server side?

Description: displays custom errors only to remote clients and errors to local hosts


Therefore, asp web.config error, do not shut down customErrors in the production environment. It is recommended to turn on remoteonly or on and define a custom error page.

The above is the whole content of this article. I hope it will help you in your study, and I hope you can support developepaer more.


Leave a Comment