Asp.net 如何清除Web.config中继承的customErrors元素?

Asp.net 如何清除Web.config中继承的customErrors元素?,asp.net,inheritance,web-config,custom-errors,Asp.net,Inheritance,Web Config,Custom Errors,正如文章所说 特定网站的Web.config文件 站点包含应用于的设置 网站和继承向下 通过所有的ASP.NET 应用程序和 地点 我有“父”应用程序的这些设置 <customErrors mode="RemoteOnly" defaultRedirect="GenericError.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" red

正如文章所说

特定网站的Web.config文件 站点包含应用于的设置 网站和继承向下 通过所有的ASP.NET 应用程序和 地点

我有“父”应用程序的这些设置

<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>
<customErrors mode="RemoteOnly" />

但对于“子”应用程序,只需要这些

<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>
<customErrors mode="RemoteOnly" />

文章还说,

在集合中,配置设置 通常会添加到集合中 通过添加子元素,由删除 通过删除子元素的键名, 或者整个集合可以是 通过清除子元素清除。一 在子配置中添加了设置 文件覆盖相同的设置 父配置中的键名称 文件,除非允许重复

但不幸的是,出于某些原因,这是非法的

<customErrors mode="RemoteOnly">
    <clear/>
<customErrors/>


所以问题是如何清除继承的customErrors元素?

您是否尝试将inheritInChildApplications=“false”XML元素添加到父级(顶级)web.config中

<location inheritInChildApplications=”false”>

参考: -

不像其他配置设置那样是一个集合-您没有
调用错误处理程序,因此无法清除它们-事实上,查看文档时,CustomeErrors元素的唯一子元素是


另外,将子应用程序设置为“RemoteOnly”后,您没有提供任何自定义错误以显示给远程用户—这真的是您想要的吗?你不应该至少提供一个不同的DefaultRedirect吗?否则,您将向用户显示无用的黄色“有一个错误,但我无法向您显示详细信息”页面。

我使用ASP.NET MVC HandleErrorAttribute设置自定义错误页面。应该注意的是,更改父项也会影响所有其他“子项”,而不仅仅是相关应用程序。