title: Returning CSV from .NET Core controller
body: <p>I'm having trouble having a .NET Core API Controller endpoint resolve to a CSV download.  I'm using the following code which I pulled from a .NET 4.5 controller:</p>
  <pre><code>[HttpGet]
  [Route(&quot;{id:int}&quot;)]
  public async Task&lt;HttpResponseMessage&gt; Get(int id)
  {
      string csv = await reportManager.GetReport(CustomerId, id);
      var response = new HttpResponseMessage(HttpStatusCode.OK);
      response.Content = new StringContent(csv);
      response.Content.Headers.ContentType = new MediaTypeHeaderValue(&quot;text/csv&quot;);
      response.Content.Headers.ContentDisposition = 
          new ContentDispositionHeaderValue(&quot;attachment&quot;) { FileName = &quot;report.csv&quot; };
      return response;
  }
  </code></pre>
  <p>When I hit this endpoint from my Angular 4 app, I get the following response written to the browser:</p>
  <pre><code>{
      &quot;version&quot;: {
          &quot;major&quot;: 1,
          &quot;minor&quot;: 1,
          &quot;build&quot;: -1,
          &quot;revision&quot;: -1,
          &quot;majorRevision&quot;: -1,
          &quot;minorRevision&quot;: -1
      },
      &quot;content&quot;: {
          &quot;headers&quot;: [
              {
                  &quot;key&quot;: &quot;Content-Type&quot;,
                  &quot;value&quot;: [
                      &quot;text/csv&quot;
                  ]
              },
              {
                  &quot;key&quot;: &quot;Content-Disposition&quot;,
                  &quot;value&quot;: [
                      &quot;attachment; filename=11.csv&quot;
                  ]
              }
          ]
      },
      &quot;statusCode&quot;: 200,
      &quot;reasonPhrase&quot;: &quot;OK&quot;,
      &quot;headers&quot;: [ ],
      &quot;requestMessage&quot;: null,
      &quot;isSuccessStatusCode&quot;: true
  }
  </code></pre>
  <p>My expectation is that when I hit the endpoint, the user will be prompted to download the CSV.</p>
  <p>I found <a href="https://github.com/damienbod/AspNetCoreCsvImportExport" rel="noreferrer">this</a> post on how to &quot;export&quot; a CSV in .NET Core.  The problem is that I'm retrieving the CSV in-memory from its source (an AWS S3 bucket) whereas this code seems to only work when you have an <code>IEnumerable&lt;object&gt;</code>.</p>
  <p>I'm wondering if my problem lies in either request or response headers, where there is something preventing the browser from retrieving a CSV from my API.  Here is what I see in the browser console:</p>
  <p><a href="https://i.stack.imgur.com/YCq2F.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YCq2F.png" alt="enter image description here" /></a></p>