I have an ASP.NET MVC WEB API. For several reasons (redirect because of no authorizations ..), I can't just use a simple object and return it in my controller method. Therefore I need the HttpResponseMessage class which allows me to redirect.
Currently I'm doing this:
var response = new Response { responseCode = Response.ResponseCodes.ItemNotFound }; var formatter = new JsonMediaTypeFormatter(); response.Content = new ObjectContent<Response>(response, formatter, "application/json"); .. to get the object, serialized as JSON, into the content of HttpResponseMessage. Somehow, I have the feeling that there is another, better, way to do this. Any ideas on that?