How can I return a Json response ALWAYS, it doesn't matter if the HTTP Code needs to be 200, 401, or another one.
For the HTTP 200 the Json is sent with return Ok(response); //where response is a model.
For HTTP 401 (Unauthorized) I have the following:
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content = new StringContent(msg),
ReasonPhrase = msg
});
But msg needs to be an String... I cannot make it work with a model to return a JSON.
The same happens with BadRequest or other HTTP status.