KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been struggling all day to implement error handling in my ASP.NET MVC 2 app. I've looked at a variety of techniques, but none work properly. I'm using MVC2 and .NET 4.0 (started the project before MVC3 was released; we'll upgrade after we deliver our initial release). At this point, I'll be happy to properly handle 404 and 500 errors -- 403 (authorization required) would be great, too, followed by various other specific responses. Right now, I either get all 404s, all 500s, all 302s before the 404, or all 302s before the 500. Here are my requirements (which should be pretty close to the basic requirements of HTTP): If a resource is not found, throw a 404, and display a 404-specific page with the requested URL. DO NOT return an intermediate response code like 302. Ideally, keep the requested URL, rather than showing a new URL like /Error/NotFound -- but if the latter displays, be sure we didn't return a redirect response to get it. If an internal server error occurred, throw a 500, and display a 500-specific error with some indication of what went wrong. Again, don't return an intermediate response code, and ideally don't change the URL. Here's what I'd consider a 404: Static file not found: /Content/non-existent-dir/non-existent-file.txt Controller not found: /non-existent-controller/Foo/666 Controller found, but Action not found: /Home/non-existent-action/666 Controller and action found, but the action can't find the requested object: /Home/Login/non-existent-id Here's what I'd consider a 500: Post a bad value: POST /User/New/new-user-name-too-long-for-db-column-constraint Non-data-related problem, like a Web Service endpoint not responding Some of these problems need to be identified by specific controllers or
Tags (comma-separated)
Save Edits
Cancel