What's the difference between HttpResponseException and HttpException
asp.net-mvc
Solution
[Moved my update to an answer]
While typing that out, I had an idea. I tried both from two controllers, an ApiController and a standard MVC controller.
The two exception work in reverse to each other depending on the type of controller they're thrown from.
- Use HttpResponseException to return a proper HTTP code from an API controller.
- Use HttpException to return a proper HTTP code from an MVC controller.
Problem
From http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling HttpResponseException What happens if a Web API controller throws an exception? By default, most exceptions are translated into an HTTP response with status code 500, Internal Server Error. The HttpResponseException type is a special case. This exception returns any HTTP status code that you specify in the constructor of the exception. Except that it doesn't. Fiddler shows me a 500 is returned. However, HttpException seems to do what that article says. Is the documentation wrong or am I missing something? UPDATE While typing that out, I had an idea. I tried both from two controllers, an ApiController and a standard MVC controller. The two exception work in reverse to each other depending on the type of controller they're thrown from. - Use HttpResponseException to return a proper HTTP code from an API controller. - Use HttpException to return a proper HTTP code from an MVC controller.