【问题标题】:How to use custom errors on IIS with ASP.NET如何通过 ASP.NET 在 IIS 上使用自定义错误
【发布时间】:2012-07-25 09:14:47
【问题描述】:

我已在我的 asp.net Web 应用程序中修改了我的 web.config 文件,以便显示自定义错误页面:

<configuration>
    <system.web>
       ...snip
        <customErrors mode="On" defaultRedirect="WebForms/ErrorPage.aspx">
          <error statusCode="404" redirect="WebForms/ErrorPageNotFound.aspx" />
        </customErrors>        
    </system.web>  
</configuration>

当我在 IIS 上运行该站点时,出现以下错误:

Error code: 0x800700b7
Config section 'system.web/customErrors' already defined. 
Sections must only appear once per config file. 
See the help topic <location> for exceptions 

很明显,我在这里有一些配置层次结构,但我不知道我需要查看哪个文件(我的机器上有 276 个 web.config 文件)——有人能指出我正确的方向吗?

当我找到该文件时,我是否可以只删除顶级 customErrors 部分,或者这是否会导致同一台机器上未定义 customErrors 的其他 Web 应用程序出现问题?

【问题讨论】:

    标签: asp.net visual-studio-2010 iis-7 webforms web-config


    【解决方案1】:

    应在根 web.config 上修改该部分

    如果您收到该错误,可能您的主应用程序的子目录中有多个 web.config,您应该开始检查这些以删除它们

    很明显,我在这里有一些配置层次结构,但我不知道我需要查看哪个文件(我的机器上有 276 个 web.config 文件)- 谁能指出我正确的方向。

    您为什么不简单地使用 windows 搜索来查找包含字符串 customErrors

    的文档

    启用 Windows 7 高级搜索:

    http://answers.microsoft.com/en-us/windows/forum/windows_7-files/in-windows-7-i-want-to-search-for-all-files/aadfe1f1-4a33-406b-8e72-bb920efa4f30

    配置文件层次结构

    1. 全球机器。 &lt;windir&gt;\Microsoft.NET\Framework\&lt;ver&gt;\Config\Machine.config
    2. 根 Web 配置。 &lt;windir&gt;\Microsoft.NET\Framework\&lt;ver&gt;\Config\Web.config
    3. 网站。 &lt;wwwroot&gt;\Web.config
    4. Web 应用程序。 &lt;wwwroot&gt;|IIS Web Site path\&lt;webapp&gt;\Web.config
    5. 文件夹。 &lt;wwwroot&gt;|IIS Web Site path\&lt;webapp&gt;\&lt;dir&gt;\Web.config

    【讨论】:

    • 我在哪里可以找到根 web.config 在 c:\inetpub\wwwroot 中没有任何内容?我尝试了高级搜索,但它甚至没有找到我的应用程序 web.config 文件(!)
    • 我的意思是你的应用程序的根配置文件。无论如何,我更新了我的答案以向您展示 ASP.Net 配置层次结构
    猜你喜欢
    • 2011-06-10
    • 2021-05-15
    • 2014-10-07
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    相关资源
    最近更新 更多