添加默认路径时,HttpError iis config抛出异常

Nei*_*eil 8 asp.net iis-7 web-config custom-error-pages

我有这个配置工作,并正确重定向以下错误

<httpErrors errorMode="Custom" 
        existingResponse="Replace" 
        defaultResponseMode="ExecuteURL" >
  <remove statusCode="403" />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" responseMode="ExecuteURL" path="/Error/AccessDenied" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/PageNotFound" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/ApplicationError" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)

但是当我添加以下默认路径以尝试添加catch all时

<httpErrors errorMode="Custom" 
        existingResponse="Replace" 
        defaultResponseMode="ExecuteURL" 
        defaultPath="/Error/ApplicationError">
Run Code Online (Sandbox Code Playgroud)

服务器抛出web.config错误

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Module     CustomErrorModule
Run Code Online (Sandbox Code Playgroud)

现在,这与msdn上文档直接相矛盾

任何帮助将不胜感激!!

Vla*_*nko 8

使用defaultPath属性可防止错误节点中使用path属性.所以下面的配置会起作用(但是当然它会为这里定义的所有HTTP错误显示相同的错误页面):

<httpErrors errorMode="Custom" existingResponse="Replace"
  defaultResponseMode="ExecuteURL" defaultPath="/Error/ApplicationError">
  <remove statusCode="403" />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" responseMode="ExecuteURL" />
  <error statusCode="404" responseMode="ExecuteURL" />
  <error statusCode="500" responseMode="ExecuteURL" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)

相关文档:https://msdn.microsoft.com/en-us/library/ms690576(v = vs.90).aspx

  • 我担心它不起作用 - 它会显示"缺少必需属性'路径'",因为你没有为"错误"条目指定路径属性.你试过配置了吗?它有用吗?我只是想知道因为在IIS7上我得到了我刚才描述的错误. (2认同)

Moh*_*our 6

由于 applicationhost.config 锁定了该属性,因此您无法覆盖 IISExpress 中的 httpErrors "defaultPath" 属性:

<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">
Run Code Online (Sandbox Code Playgroud)

您可以在此处阅读更多相关信息:https : //support.microsoft.com/en-us/kb/942055可能会出现此问题:

当 IIS 配置文件的指定部分被锁定在更高的配置级别时。要解决此问题,请解锁指定的部分,或者不要在该级别使用它。有关配置锁定的详细信息,请参阅如何在 IIS 7.0 配置中使用锁定


小智 -2

尝试defaultPath="~/Error/ApplicationError"用〜。