Last post Aug 31, 2015 05:02 AM by Caillen Zhong
Aug 04, 2015 09:40 PM|PhC|LINK
I would like to return some HttpStatusCode (e.g. OK, Created, Accepted, Unauthorize, Not Found, RequestTimeout and InternalServerError with msg) in Controller. Since I have multiple methods in controllers, I want to implement it in a common file (i.e. controller.cs)
and inherits all controllers to this file.
However, I'm not sure how to return HttpStatusCode correctly in WEBAPI. Is there any method to return it correctly?
Aug 04, 2015 11:55 PM|santhoshje|LINK
Please return http status code like this
public IHttpActionResult GetCustomer(int id)
var customer = db.Customers.ToList();
if (question == null)
Aug 05, 2015 04:25 AM|PhC|LINK
Finally I find following method in Internet and try to apply it.
However, is it possible to return an object with http status code (OK)?
Aug 31, 2015 05:02 AM|Caillen Zhong|LINK
Please try to return
HttpResponseMessage object which can hold the object you want to return, as well as the status code specified:
If it's an exception, wrap it with
Sample code is provided in the above documents.