title: ASP.Net Core 2.0 How to get all request headers in middleware?
body: <p>In ASP.Net Core 2.0, I am trying to validate the incoming request headers in a custom middleware.</p>
  
  <p>The problem is that I don't how to extract all the key-value-pair headers. The headers that I need are stored in a protected property </p>
  
  <pre><code>protected Dictionary&lt;string, stringValues&gt; MaybeUnknown
  </code></pre>
  
  <p>My middleware class looks like this so far:</p>
  
  <pre><code>public class HeaderValidation
  {
      private readonly RequestDelegate _next;
      public HeaderValidation(RequestDelegate next)
      {
          _next = next;
      }
  
      public async Task Invoke(HttpContext httpContext)
      {
          IHeaderDictionary headers = httpContext.Request.Headers; // at runtime headers are of type FrameRequestHeaders
  
          // How to get the key-value-pair headers?
          // "protected Dictionary&lt;string, stringValues&gt; MaybeUnknown" from headers is inaccessbile due to its protection level
          // Casting headers as Dictionary&lt;string, StringValues&gt; results in null
  
          await _next.Invoke(httpContext);
      }
  }
  </code></pre>
  
  <p>My goal is to extract all request headers and not only a few selected headers for which I must know the specific keys.</p>