Asp.net Mvc Return Error 404
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings aspnet mvc nuget and policies of this site About Us Learn more about Stack Overflow
Aspnet Mvc Source
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation aspnet mvc tutorial Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it
Aspnet Mvc 5
only takes a minute: Sign up How to get MVC action to return 404 up vote 94 down vote favorite 12 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 aspnet mvc 4 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? asp.net-mvc error-handling http-status-code-404 share|improve this question asked Jun 1 '10 at 9:14 Paul Hiles 5,05032962 you also have to keep Response.TrySkipIisCustomErrors = true; The answer by @ganders was a life saver... –Thunder Jan 10 '15 at 11:28 add a comment| 11 Answers 11 active oldest votes up vote 73 down vote accepted There are multiple ways to do it, You are right in common aspx code it can be assigned in your specified way throw new HttpException(404, "Some description"); share|improve this answer edited Jul 29 '15 at 20:33 Christian Gollhardt 4,18172245 answered Jun 1 '10 at 9:18 Dewfy
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Aspnet Mvc Cms
this site About Us Learn more about Stack Overflow the company Business
Aspnet Mvc 6
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask aspnet mvc 3 Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign http://stackoverflow.com/questions/2948484/how-to-get-mvc-action-to-return-404 up Returning a custom 404 page with 404 statuscode in MVC? up vote 5 down vote favorite I'm trying to return a 404 status code with my custom error page. However I keep getting 200 back, since the page does actual exists as far as the browser and server can tell. What I have been trying so far is:
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://stackoverflow.com/questions/1998328/throwing-returning-a-404-actionresult-or-exception-in-asp-net-mvc-and-letting-ii About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up throwing/returning a 404 actionresult or aspnet mvc exception in Asp.net MVC and letting IIS handle it up vote 36 down vote favorite 5 how do I throw a 404 or FileNotFound exception/result from my action and let IIS use my customErrors config section to show the 404 page? I've defined my customErrors like so