title: How to specify ContentType for Web API controller method
body: <p>There's a Request object, and getting the request content type is easy. But how do you <em>specify</em> a content type for the response? My controller looks like this (other actions excised for brevity):</p>
  
  <pre><code>public class AuditController : ApiController
  {   
    // GET api/Audit/CSV
    [HttpGet, ActionName("CSV")]
    public string Csv(Guid sessionId, DateTime a, DateTime b, string predicate)
    {
      var result = new StringBuilder();
      //build a string
      return result.ToString();
    }
  }
  </code></pre>
  
  <p>This works fine except that it has the wrong content type. I'd like to do this</p>
  
  <pre><code>Response.ContentType = "text/csv";
  </code></pre>
  
  <p>A little research reveals that we can type the Action to return an HttpResponseMessage. So the end of my method would look like this:</p>
  
  <pre><code>  var response = new HttpResponseMessage() ;
    response.Headers.Add("ContentType","text/csv");
    response.Content = //not sure how to set this
    return response;
  </code></pre>
  
  <p>The documentation on HttpContent is rather sparse, can anyone advise me on how to get the contents of my StringBuilder into an HttpContent object?</p>