How to get MVC action to return 404

Posted by zaph0d on Stack Overflow See other posts from Stack Overflow or by zaph0d
Published on 2010-06-01T09:14:15Z Indexed on 2010/06/01 9:23 UTC
Read the original article Hit count: 205

I have an action that takes in a string that is used to retrieve some data. If this string results in no data being returned (maybe because it has been deleted), I want to return a 404 and display an error page.

I currently just use return a special view that display a friendly error message specific to this action saying that the item was not found. This works fine, but would ideally like to return a 404 status code so search engines know that this content no longer exists and can remove it from the search results.

What is the best way to go about this?

Is it as simple as setting Response.StatusCode = 404?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about error-handling