In my WebAPI class, an ApiController, I make a call such as:
string myCustomMessage = .....;
throw new HttpResponseException(
new HttpRespo
Try returning HttpResponseMessage like this.
public HttpResponseMessage Get()
{
return Request.CreateErrorResponse(
HttpStatusCode.Unauthorized, "You are not authorized");
}
This should produce an HTTP response message like this.
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
Date: Sat, 12 Apr 2014 07:12:54 GMT
Content-Length: 36
{"Message":"You are not authorized"}