How to clear inherited customErrors elements in Web.config?
-
13-09-2019 - |
Question
As the article ASP.NET Configuration File Hierarchy and Inheritance says
the Web.config file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site.
I have these settings for a "parent" application
<customErrors mode="RemoteOnly" defaultRedirect="GenericError.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
<error statusCode="500" redirect="InternalError.htm" />
</customErrors>
but need only these for a "child" application
<customErrors mode="RemoteOnly" />
The article also says
In collections, configuration settings are typically added to the collection via an add child element, removed by key name via a remove child element, or the entire collection can be cleared via a clear child element. An added setting in a child configuration file overrides a setting of the same key name in a parent configuration file unless duplicates are allowed.
But unfortunately this is illegal for some reason
<customErrors mode="RemoteOnly">
<clear/>
<customErrors/>
So the question is how to clear inherited customErrors elements?
Solution
Did you try to add in the inheritInChildApplications="false" XML element to your parent's (top level) web.config?
<location inheritInChildApplications=”false”>
reference: - http://www.west-wind.com/WebLog/posts/133041.aspx
OTHER TIPS
CustomErrors isn't a collection like other config settings - you're not <add />
ing the error handlers, so you can't clear them - indeed looking at the docs, the only Child of the CustomerErrors element is <error>
.
Also, having set the child application to "RemoteOnly" you aren't supplying any custom errors to show to remote users - is that really what you want? Shouldn't you at least be supplying a different DefaultRedirect? Otherwise you'll be showing users the useless yellow "There was an error, but I can't show you the details" page.