Return file in ASP.Net Core Web API

Problem I want to return a file in my ASP.Net Web API Controller, but all my approaches return the HttpResponseMessage as JSON. Code so far public async Task<HttpResponseMessage> DownloadAsync(string id) { var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent({{__insert_stream_here__}}); response.Content.Headers.ContentType = new MediaTypeHeaderValue(“application/octet-stream”); return response; } When I call this endpoint in my browser, … Read more

ASP.NET Core return JSON with status code

I’m looking for the correct way to return JSON with a HTTP status code in my .NET Core Web API controller. I use to use it like this: public IHttpActionResult GetResourceData() { return this.Content(HttpStatusCode.OK, new { response = “Hello”}); } This was in a 4.6 MVC application but now with .NET Core I don’t seem … Read more