I am making from a ApiController a direct SQL query (SQL Server 2014) to the DB:
public object Post(JObject jsonData){
//..
string qvalue = "SELECT s.Id, v.[Name] VehicleId, s.TimestampLocal FROM Status s INNER JOIN Vehicles v on s.VehicleId = v.Id";
var resl = entities.Database.SqlQuery<StatusTime>(qvalue);
return resl;
The response arrives to the client as Content-Type: "application/json; charset=utf-8". I want to change the Content-Type to something else like: "application/json" or even "text/xml".
I have tried adding before "return resl;" the line:
HttpContext.Current.Response.ContentType = "application/json";
but it does not change it.
I have tried adding something to the header (just to see the response changed) and the header is changed (and arrives at the client changed) with:
HttpContext.Current.Response.AppendHeader("test", "hello");
I have seen this example: HttpContext.Current.Response.AddHeader() not setting Content-Type header
and indeed it sets the content type but I have no idea how to apply it to a SqlQuery result. Also I do not want to bring the data to the IIS server with .ToList or similar and then write it to the response because it is massive (~80MB).
I have seen this too: WebAPI to Return XML
and: Change Content-Type header for HttpResponseMessage
How could this be done, or is this decided for me by the controller?