IIS7.5 URLRewrite无法处理自定义404错误页面

时间:2018-06-08 09:55:35

标签: asp.net url-rewriting iis-7.5

我在IIS 7.5上使用URL Rewrite来隐藏ASP.NET Webforms应用程序的服务器公开标题,并且在我的主应用程序中一切正常。但是,在自定义错误处理方面,重写根本不会触发。

在我的web.config中:

    <outboundRules>
        <remove name="Remove Server header" />
        <rule name="Remove Server header" enabled="true">
            <match serverVariable="RESPONSE_SERVER" pattern=".+" />
            <action type="Rewrite" value=" " />
        </rule>
    </outboundRules>

同样在以下部分:

<modules runAllManagedModulesForAllRequests="true" />

HTTP错误:

<httpErrors errorMode="Custom">
  <remove statusCode="404" />
  <error statusCode="404" responseMode="ExecuteURL" path="/404Check.aspx" />
</httpErrors>

自定义错误:

  <customErrors mode="On" >
      <error statusCode="404" redirect="~/404Check.aspx"/>
 </customErrors>

在自定义404页面上,它只是查找用于处理登录尝试的几个值。如果未找到任何值,则会向用户显示错误消息。

有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

实际上在其他地方找到了一个很好的答案。问题在于对404页面的内部重定向,它似乎完全绕过了URLRewrite。

Using ExecuteURL as 404 handler in web.config will bypass URL Rewrite (ie.. outboundRules) while using other responseModes won't