0

I'm building an api using ASP.NET MVC 3. When a controller action is not found I don't want the standard message and result returned. I want to respond with a json message containing additional data about the request. How can I override the default behavior which gives me the plain "Resource not found" page?

thanks!

Micah
  • 111,873
  • 86
  • 233
  • 325

2 Answers2

4

There's a great thread on here regarding this with very "MVCish" ways outside of generic error handling. There are multiple ways to do it - so rather than just repeat the thread, check it out: How can I properly handle 404 in ASP.NET MVC?

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
2

Add the following to your web config and set up a route for the redirect.

<customErrors mode="On" >
       <error statusCode="404" redirect="/Errors/Error404/" />
</customErrors>
spender
  • 117,338
  • 33
  • 229
  • 351