简体   繁体   中英

IIS7.5 URLRewrite not working on custom 404 Error page

I am using URL Rewrite on IIS 7.5 to hide the server disclosure header for an ASP.NET Webforms application and everything is working fine in my main application. However, on custom error handling, the rewrite is not firing at all.

In my 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>

Also in the section:

<modules runAllManagedModulesForAllRequests="true" />

HTTP Errors:

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

Custom errors:

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

On the custom 404 page, it simply looks for a couple of values for processing a login attempt. If no values are found, it displays an error message to the user.

Is there something I'm missing?

Actually found a great answer to this elsewhere. The issue was to do with an internal redirection to the 404 page, which appeared to bypass URLRewrite completely.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM