-
Hi, I’m currently exploring ways to selectively forward requests either to local controllers or downstream services based on a custom flag. While utilizing the Order property seems to be the most straightforward approach for routes with the same pattern, it only works effectively when the route configuration in YARP and the route for the local controller are identically specific, as the most specific match wins. Here’s the scenario I’m dealing with:
With this setup, a request matching "controller/action1" naturally hits the local endpoint. However, I want to have the flexibility to selectively proxy this request based on a custom flag, even when it matches the local route. Is there a way I can manually control whether a request gets proxied or not within a middleware component? Alternatively, if there’s another approach or strategy that could achieve this selective forwarding, I’m open to suggestions and would appreciate any insights. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Yes, in the middleware you can check the HttpContext to see if you want to forward. If so, you call IHttpForwarder, else call the next middleware. This will show you how to get and call the IHttpForwarder. |
Beta Was this translation helpful? Give feedback.
Yes, in the middleware you can check the HttpContext to see if you want to forward. If so, you call IHttpForwarder, else call the next middleware.
This will show you how to get and call the IHttpForwarder.
https://microsoft.github.io/reverse-proxy/articles/direct-forwarding.html