R – How to clear inherited customErrors elements in Web.config

asp.netcustom-errorsinheritanceweb.config

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?

Best Answer

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

Related Topic