title: Adding header values in Filter to use as Action parameters in Controller
body: <p>I use Windows Authentication with my application and have a <code>UserInfo</code> table in my database to store information about the user. I keep the <code>UserId</code> for this table in the user's Session. Dealing with the Session and its extension methods is causing problems with Unit Tests, so I wanted to stop using it in Controller Actions.</p>
  
  <p>I tried reading it from the Session and adding it to Request Headers in a filter:</p>
  
  <pre><code>    public void OnActionExecuting(ActionExecutingContext context)
      {
          Controller controller = (Controller)context.Controller;
  
          context.HttpContext.Request.Headers.Add("userId", context.HttpContext.Session.GetString("UserId"));
      }
  </code></pre>
  
  <p>Then using <code>[FromHeader]</code> to get the value in Actions that need it:</p>
  
  <pre><code>    [HttpGet]
      public async Task&lt;IActionResult&gt; MyAction(Guid? id, [FromHeader]string userId)
      {
  
      }
  </code></pre>
  
  <p>But the problem is the <code>userId</code> parameter here is always <code>null</code>. I can see the <code>userId</code> value when debugging if I inspect <code>HttpContext.Request.Headers.Unknown</code> though.</p>