I was wondering if it’s possible to access the controller being executed (or about to be executed) in the SendAsync method of the DelegatingHandler? I can’t seem to figure out how to get access to it, and I figure it’s because it executes outside of the controller execution…
Is it possible to refer to it?
No, because message handlers operate on raw
HttpRequestMessageor rawHttpResponseMessage(in case of continuations). So really, there is no concept of “current controller executing” withDelegatingHandlerssince message handlers will be called before dispatching the request to the controller or (again, in the case of continuations) after the controller returns the reponse.However, it really depends what you are trying to do.
If you want to know to which controller the request will end up getting routed, you can manually call the mechanism that would internally select the controllers.