Micah
Micah

Reputation: 116100

How can I override the 404 response in MVC 3?

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!

Upvotes: 0

Views: 249

Answers (2)

Adam Tuliper
Adam Tuliper

Reputation: 30152

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?

Upvotes: 4

spender
spender

Reputation: 120470

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>

Upvotes: 2

Related Questions