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.

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.