Custom Error Pages Except in a Sub Folder
I tried all the complex ways to do something which turned out to be quite simple.
I had a need to show nice-looking custom error page in my asp.net application for all folders except one. That special folder needed to return a proper error code and not a 302 (redirect to a custom error page) status.
While it was simple enough to make the custom error page set a Response.StatusCode = 500, I could tell with my Http Proxy sniffing tool Fiddler that the first code sent was the 302. This wasn’t good. I had to be sure that if there was an error, that the requesting client got an error code, not a redirect code, and worse yet, a redirect to a 200 OK code.
The solution was simple: in my application’s web.config, set a location-specific customErrors directive:
<location path="specialFolder">
<system.web>
<customErrors defaultRedirect="" mode="RemoteOnly"></customErrors>
</system.web>
</location>
The important part here is to specify a defaultRedirect="". This solved my issue, and is now good again.

Comments