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
  • 106,911
  • 83
  • 226
  • 321

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,829
  • 4
  • 51
  • 70
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
  • 112,247
  • 30
  • 221
  • 334