I have a custom ActionResult for returning certain HTTP Errors, like NotFoundResult and ForbiddenResult, they all derive from ViewResult.
I use them for instances like short circuiting actions with a 404 if an entity was not found in the database during the course of an action.
Within these result objects, I set the HTTP Status to the appropriate number. When I do that, the view that these ViewResults reference does not render. I have to leave the status as 200 OK in order for my view to be rendered.
How do I set an appropriate status AND render a view in ASP.NET MVC 2.0?
Allow me to suggest you an alternative error handling:
Start by creating an error controller and the corresponding views:
In
Global.asax
define theApplication_Error
method:Finally throw appropriate exceptions: