I'm working with ASP.Net MVC 5
and Web Api 2 Controller
and I'm facing a really annoying thing.
When I send an HttpResponseMessage
using, for example, a 400
status code, I would like to send a string
message with the reason.
If I return an HTTP 200
the content is displayed correctly, but if I do something like this:
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StringContent("This is a bad request man.");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/text");
response.StatusCode = HttpStatusCode.BadRequest;
return response;
It doesn't seem to work.
Is this a bad practice? Am I wrong when I think that I should return a message in this case?
Thanks in advance!