Unable to get request header in asp net core web API
How about this one? We shoule embrace the new variables. :)
bool tryGetValue = actionContext.ActionArguments.TryGetValue("data", out data);
public static class HttpRequestExtension
{
public static string GetHeader(this HttpRequest request, string key)
{
return request.Headers.FirstOrDefault(x => x.Key == key).Value.FirstOrDefault();
}
}
calling method:
var Authorization = Request.GetHeader("Authorization");
Thank you all for your valuable input however below code worked as expected.
actionContext.HttpContext.Request.Headers.TryGetValue("Authorization", out authorizationToken);