I want to deal with exceptions in the WebAPI action method, catching them by setting the status code and writing a message in the response. Normally in normal MVC, ControllerI would do it this way using the property Controller Response:
Response.StatusCode = 404;
Response.Write("Whatever");
However, it seems to ApiControllerhave no property Response. Is there a reason for this? Can it just be used HttpContext.Current.Responseas follows :?
HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.Write("Whatever");
Or is there a specific way to record a response from a WebAPI controller?
source
share