title: Cannot set Content-MD5 header in WebApi Response
body: <p>When I try to set the <code>Content-MD5</code>-Header I get this exception</p>
  
  <pre><code>System.InvalidOperationException wurde nicht von Benutzercode behandelt.
    HResult=-2146233079
    Message=Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
    Source=System.Net.Http
    StackTrace:
         bei System.Net.Http.Headers.HttpHeaders.CheckHeaderName(String name)
         bei System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
         bei caching_test.Controllers.ValuesController.Get(Int32 id) in C:\Users\ulbricht\Documents\Bitbucket\caching-system\caching test\Controllers\ValuesController.cs:Zeile 35.
         bei lambda_method(Closure , Object , Object[] )
         bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass13.&lt;GetExecutor&gt;b__c(Object instance, Object[] methodParameters)
         bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
         bei System.Web.Http.Controllers.ReflectedHttpActionDescriptor.&lt;&gt;c__DisplayClass5.&lt;ExecuteAsync&gt;b__4()
         bei System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
    InnerException: 
  </code></pre>
  
  <p>This is the part with the exception</p>
  
  <pre><code>public HttpResponseMessage Get(int id)
  {
      var result = "value" + id;
      var hash = Convert.ToBase64String(MD5.Create().ComputeHash(UTF8Encoding.UTF8.GetBytes(result)));
      if (Request.Headers.FirstOrDefault(h =&gt; h.Key == "Content-MD5").Value != null)
      {
          var hashvalue = Request.Headers.FirstOrDefault(h =&gt; h.Key == "Content-MD5").Value.FirstOrDefault();
          if (hashvalue == hash)
          {
              return Request.CreateResponse(HttpStatusCode.NotModified);
          }
      }
      var response = Request.CreateResponse(HttpStatusCode.OK, result);
      response.Headers.Add("Content-MD5", hash); // &lt;------- Here comes the error
      return response;
  }
  </code></pre>
  
  <p>Here is the sourcecode <a href="https://bitbucket.org/Knerd/caching-system" rel="nofollow">https://bitbucket.org/Knerd/caching-system</a> I hope you can help me.</p>