无法读取配置节"httpErrors",因为它缺少节声明

无法读取配置节

问题描述:

我正在尝试通过适应< httpErrors> 的配置示例.我在Web.config中添加了<httpErrors>,但是却得到了HTTP Error 500.19The configuration section 'httpErrors' cannot be read because it is missing a section declaration.

I am trying to configure a custom error page for the 403 Forbidden response in my WebApi application by adapting Example of Configuration for <httpErrors>. I added <httpErrors> to my Web.config but I'm getting HTTP Error 500.19 and The configuration section 'httpErrors' cannot be read because it is missing a section declaration.

我该如何解决?

我的代码:

<system.web>
  ....
  <httpErrors errorMode="Custom">
    <remove statusCode="403" subStatusCode='-1' />
    <error statusCode="403" path="/forbidden.html" prefixLanguageFilePath="" responseMode="ExecuteURL"  />
  </httpErrors>
</system.web>

错误的屏幕截图:

从注释中复制.

这些错误消息很清楚,这要求您转至IIS参考文档以学习实际的部分.

Such error messages are clear, which requires you to go to IIS reference documentation to learn the actual sections.

https://docs.microsoft.com/zh-cn/iis/configuration/system.webserver/httperrors/

然后很明显,httpErrorssystem.webServer下的一个部分,而不是system.web.

Then it is obvious that httpErrors is a section under system.webServer, not system.web.