I am trying to create a custom filter in asp net core web api which is as below but unable to get header info.
internal class BasicAuthFilterAttribute : ActionFilterAttribute
{
private StringValues xyz;
public override void OnActionExecuting(ActionExecutingContext actionContext)
{
var authHeader = actionContext.HttpContext.Request.Headers.TryGetValue("Basic", out xyz);
}
}
TryGetValue
always return false however I can see Headers
contains the "Basic" header. As I am new in ASP.NET Core so can anyone guide me what I am possibly doing wrong?
Thank you all for your valuable input however below code worked as expected.
actionContext.HttpContext.Request.Headers.TryGetValue("Authorization", out authorizationToken);