未找到上下文的 DownstreamContext

DownstreamContext of context not found

我正在尝试添加自定义中间件以向查询添加参数。

根据一些网上搜索,你可以这样做:

{
            //PreQueryStringBuilderMiddleware occurs after authorization
            PreQueryStringBuilderMiddleware = async (ctx, next) =>
            {
                var upstreamRoute = ctx.DownstreamReRoute.UpstreamPathTemplate;
                Log.Information($"{upstreamRoute}");
                await next.Invoke();
            }
        };

See this answer

但对我来说,它说 HttpContext 不包含 DownstreamReRoute 的定义。
有没有我遗漏的东西或者这个已经改变了?

好的,事实证明这确实发生了变化,并且在早期版本中仍然有效。但从我读到的来看,Ocelot 似乎已经死了。

var upstreamRoute = ctx.Items.DownstreamRoute().UpstreamPathTemplate

使用上面的代码代替 var upstreamRoute = ctx.DownstreamReRoute.UpstreamPathTemplate;

此类更改是在 15.0.6 和 16.0.0 Ocelot 版本之间完成的。 有关详细信息,您可以在 github 上查看它们:https://github.com/ThreeMammals/Ocelot/compare/15.0.6...16.0.0