I am trying to read the URL parameters sent to an WEB API Action Method using the IHttpContextAccessor interface and its default implementation HttpContextAccessor from within a DelegatingHandler.
The controller looks like this:
[HttpPost("{siteName}/{accountID}")]
public async Task<ActionResult<AirRequest>> Post(AirCModel model, string siteName, string accountID)
{
}
I want to read the value {siteName}/{accountID} within a DelegatingHandler
public class AuthenticationDelegatingHandler : DelegatingHandler
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AuthenticationDelegatingHandler(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var siteNAme = _httpContextAccessor ???
}
}
in the Startup.cs I injected the HttpContext Service:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddHttpContextAccessor();
}