title: Unable to add Access-Control-Allow-Origin header on API response
body: <p>I am currently converting a project from .Net Framework into .Net 5.</p>
  <p>When I hit one of the endpoints within the new .Net 5 project I get the following exception.</p>
  <blockquote>
  <p>System.InvalidOperationException: 'Misused header name,
  'Access-Control-Allow-Origin'. Make sure request headers are used with
  HttpRequestMessage, response headers with HttpResponseMessage, and
  content headers with HttpContent objects.'</p>
  </blockquote>
  <p>The endpoint looks like this, the exception is thrown on the line where I add &quot;Access-Control-Allow-Origin&quot; onto the response content header.</p>
  <pre><code> [HttpGet]
              [Route(&quot;api/Recommendations/GetRecommendations/{id}/{count}&quot;)]
              public HttpResponseMessage GetRecommendations(int id, int count)
              {
  
                  var response = new HttpResponseMessage();
                  response.Content = new StringContent(_recommendationsAPIService.GetRecommendations(id, count));
                  response.Content.Headers.ContentType = new MediaTypeHeaderValue(&quot;application/json&quot;);
                  response.Content.Headers.Add(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
                  response.Content.Headers.Add(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type, Accept, Referer, Authorization,Sec-Fetch-Mode,User-Agent&quot;);
                  return response;
              }
  </code></pre>
  <p>How do I fix this exception?</p>
  <p>I am not familiar with who originally wrote the project so is there any reason to add these headers onto the response anyway?</p>