title: How do you cast a filtered list of HttpRequestHeaders from Request?
body: <p>I'm attempting to filter my list of headers that was returned by <code>Request.Headers</code>:</p>
  
  <pre><code>var validHeaders = (HttpRequestHeaders)Request.Headers.Where(header =&gt; ValidHeaders.List.Contains(header.Key.ToUpper()));
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/jSvsq.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jSvsq.gif" alt="enter image description here"></a></p>
  
  <p>I am getting the following exception:</p>
  
  <blockquote>
    <p>System.InvalidCastException: 'Unable to cast object of type
    'WhereEnumerableIterator<code>1[System.Collections.Generic.KeyValuePair</code>2[System.String,System.Collections.Generic.IEnumerable`1[System.String]]]'
    to type 'System.Net.Http.Headers.HttpRequestHeaders'.'</p>
  </blockquote>
  
  <p><strong>How do I cast a Request.Headers.Where expression into a HttpRequestHeaders?</strong></p>