I have implemented custom errors in my asp.net mvc application by following this article. What I have noticed is that if I go to http://www.mysite.com/some-non-existent-controller-and-action I get my 404 error page as expected. However, looking at what happens with firebug, I see that I get a 302 Found response for the non-existent page, which then redirects to my custom error page which then returns with a 404 (and displays the custom error page). Is this right? I don’t think the 302 that is first returned is very good especially from an SEO perspective, and that maybe I need to think again about how I have implemented this.
I have implemented custom errors in my asp.net mvc application by following this article
Share
The best guide(i think) for handling 404s can be found in this answer. Basically there are multiple ways in which 404s can happen:
{controller}/{action}/{parameter}rule.HandleUnknownActionoverride.The linked answer basically sets up a controller that can be executed from any point in the code without rewriting the URL – which is what you want.
In addition, you should also think about handling unhandled exceptions and bad URLs (like the ones containing unsafe characters like angle brackets). I that particular case you have to rewrite the URL, otherwise you can’t render the response at all. These particular requests are kind of tricky, i blogged about that here.