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
The <customErrors> section in Web. config has two attributes that affect what error page is shown: defaultRedirect and mode . The defaultRedirect attribute is optional. If provided, it specifies the URL of the custom error page and indicates that the custom error page should be shown instead of the Runtime Error YSOD.
You can use the <customErrors> in web. config to display custom pages when exceptions occurred in MVC application with the response status code 200. For SEO reason, you may want to display a custom error page and return an appropriate error code in ASP.NET webform or MVC application.
The <customErrors> element under system. web in web. config is used to configure error code to a custom page. It can be used to configure custom pages for any error code 4xx or 5xx.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With