Get request-header in web api
<p>I'm trying to set a header with a simple key/value-pair and want to read this from my API.
So this is my call from client:</p>

<pre><code>public async Task&lt;T&gt; Auth_GetAsync&lt;T&gt;(string path)
{
    var client = BaseHttpClient;
    var request = new HttpRequestMessage
    {
        RequestUri = new Uri(Path.Combine(client.BaseAddress.AbsoluteUri, path)),
        Method = HttpMethod.Get,
        Headers = { {"key", "param"} }
    };
    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(RequestHeader));
    var task = await client.SendAsync(request);
    return task.IsSuccessStatusCode
                    ? JsonConvert.DeserializeObject&lt;T&gt;(await task.Content.ReadAsStringAsync())
                    : default(T);
}
</code></pre>

<p>when I'm trying to read the header in my action, I get it completely (with my key/value-pair)</p>

<pre><code>public async Task&lt;IEnumerable&lt;string&gt;&gt; GetAsync()
{
    var i = Request.Headers;
    return await Task.Run(() =&gt; new[] { "value1", "value2" });
}
</code></pre>

<p>when I'm trying to do this with the ActionFilterAttribute and/or the IAuthorizationFilter my header always contains other keys, but never contains my key/value-pair.
This is my Attribute:</p>

<pre><code>public class RequiresKeyAttribute : ActionFilterAttribute, IAuthorizationFilter
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var req = filterContext.HttpContext.Request;
        var auth = req.Headers["key"]; // this is null here
    }

    public void OnAuthorization(AuthorizationContext filterContext)
    {
        var i = filterContext.HttpContext.Request.Headers;
    }
}
</code></pre>

<p>My target is, that the actionfilter checks whether the key is set in the header or not. I don't always want to check in my action if the key is set and validate it,...</p>

<p>Am I doing something wrong? Or is there solution to do this?</p>