I am developing some restful web service using .net web api.
I need to return 404 (NotFoundStatus) or 400 (BadRequest) to the client for some scenarios.
It seems like that there are many ways to do this in the framework. Following list some of the ways that I know about.
Is there any guideline of choosing which one to use for returning these response?
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Error");
return Request.CreateResponse(HttpStatusCode.NotFound, "Error");
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Error") });