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

时间:2009-09-23 13:37:47

标签: asp.net inheritance web-config custom-errors

正如文章ASP.NET Configuration File Hierarchy and Inheritance所说

  

特定Web的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" />

文章还说

  

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

但不幸的是,由于某种原因,这是非法的

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

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

2 个答案:

答案 0 :(得分:1)

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

<location inheritInChildApplications=”false”>

参考: - http://www.west-wind.com/WebLog/posts/133041.aspx

答案 1 :(得分:0)

CustomErrors不是像其他配置设置一样的集合 - 你不是<add />错误处理程序,所以你无法清除它们 - 确实在查看文档,这是唯一的子项CustomerErrors元素为<error>

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