Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC & C# : HttpStatusCodeResult() vs HttpNotFound()

In ASP.NET MVC, what is the difference between returning this:

 return new HttpStatusCodeResult(HttpStatusCode.NotFound);

and this:

 return HttpNotFound();
like image 684
patsy2k Avatar asked Mar 05 '23 16:03

patsy2k


1 Answers

The difference is that HttpStatusCodeResult gives you more control over which HTTP status code you can return as it allows you to specify any of the predefined status codes in the HttpStatusCode enum. HttpNotFound always returns the HTTP status code 404.

like image 122
silkfire Avatar answered Mar 12 '23 19:03

silkfire