I am trying to access the Request property in my ApiController-derived class.
For some reason, Request is null in ExecuteAsync method. I've seen the other questions, so before you ask:
- I am not initializing the controller by calling the constructor, it's a regular HTTP POST API call from an external device.
- I've tried the same request locally with Fiddler, the behavior is identical.
- I am not unit testing.
- Before hitting the
ExecuteAsyncmethod, my request passes through a delegating handler, and in the delegating handler, my request object exists (I even add some properties without any problem). - At the last line of delegating handler, I call
return await base.SendAsync(request, cancellationToken);without a problem andrequestexists. - Right after than in API controller,
HttpContext.Current.Requestis not null and accessible without problem. - In API controller,
RequestContextis not null and accessible without problem. - In that same line,
Requestis null.
Why would this occur? I'm on Web API 2.2 (and MVC 5, if relevant).