Reputation: 2661
On a site I run, I have 404's and 500 errors mapped to redirect to a custom error page for end users; using the following code in my web.config:
...
...
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
...
...
However, I have one specific page that I do not want redirected; a health check page to make sure the site is 100% operational. I tried setting a location specific custom error handler using the code below in my web.config:
...
...
</system.web>
<location path="health.aspx">
<system.web>
<customErrors defaultRedirect="" mode="RemoteOnly"></customErrors>
</system.web>
</location>
...
...
However, it doesn't seem to work. When I rename health.aspx to something else like badhealth.aspx, then make a request, I expect to get a generic 404 error via the Yellow Screen of Death page. Similarly, by intentionally changing the code to throw an error, I should get 500 error via the YSOD page. In both cases, I end up being redirected to our custom 404 page, rathen then getting a YSOD. Thoughts?
Any assistance is greatly appreciated.
Thanks all, - Frank
Upvotes: 6
Views: 4207
Reputation: 2661
Nevermind, we solved the issue. It seems when you have a location specific customError directive; if you leave the defaultRedirect as "", it will default to the sitewide defaultRedirect URL.
The solution was simply to turn off CustomError handling for this specific path, like so:
<system.web>
<customErrors defaultRedirect="/404/default.aspx" mode="RemoteOnly">
<error statusCode="404" redirect="/404/default.aspx" />
</customErrors>
</system.web>
<location path="health.aspx">
<system.web>
<customErrors mode="Off"/>
</system.web>
</location>
Thanks anyway, Jose.
Upvotes: 10