Is it possible to get at the header information in the constructor of a web API controller? I want to set variables based off a header value but I don't want to have to do it for each method. I'm particularly interested in a custom header value but I would settle for the Authorization one at this point. I can get it to work in an AuthorizationFilterAttribute but I also need it at the controller level.
[PolicyAuthorize]
public class PoliciesController : ApiController
{
public PoliciesController()
{
var x = HttpContext.Current; //will be null in constructor
}
public HttpResponseMessage Get()
{
var x = HttpContext.Current; //will be available but too late
}
}
public class PolicyAuthorizeAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
var authHeader = actionContext.Request.Headers.Authorization; //can get at Authorization header here but no HTTPActionContext in controller
}
}