404 尝试将上游路径路由到 Ocelot 中的下游路径
404 trying to route the Upstream path to downstream path in Ocelot
我在将传入的 http 请求转发到下游路径时遇到了这个 warning/error。
Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware:
Warning: requestId: 80000025-0004-fd00-b63f-84710c7967bb,
previousRequestId: no previous request id, message:
DownstreamRouteFinderMiddleware setting pipeline errors.
IDownstreamRouteFinder returned Error Code:
UnableToFindDownstreamRouteError Message: Failed to match Route
configuration for upstream path: /getDepartment, verb: GET.
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
config.AddJsonFile("ocelot.json");
})
.UseStartup<Startup>();
}
Startup.cs
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
await app.UseOcelot();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
ocelot.json
{
"ReRoutes": [
{
"DownstreamPathTemplate": "api/department",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44388
}
],
"UpstreamPathTemplate": "/getDepartment",
"UpstreamHttpMethod": [
"Get"
]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000"
}
}
我收到错误 404。
如果您使用的是最新版本 (16.0.0),请将 ocelot.json 中的 "ReRoutes" 更改为 "Routes"。
我遇到了同样的问题,然后遇到了这个拉取请求,解释说它已经更改为与新的 Microsoft 反向代理项目 (YARP) 相匹配。他们的文档需要更新。
https://github.com/ThreeMammals/Ocelot/pull/1239
我在将传入的 http 请求转发到下游路径时遇到了这个 warning/error。
Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware: Warning: requestId: 80000025-0004-fd00-b63f-84710c7967bb, previousRequestId: no previous request id, message: DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /getDepartment, verb: GET.
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
config.AddJsonFile("ocelot.json");
})
.UseStartup<Startup>();
}
Startup.cs
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddOcelot(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
await app.UseOcelot();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
ocelot.json
{
"ReRoutes": [
{
"DownstreamPathTemplate": "api/department",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 44388
}
],
"UpstreamPathTemplate": "/getDepartment",
"UpstreamHttpMethod": [
"Get"
]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000"
}
}
我收到错误 404。
如果您使用的是最新版本 (16.0.0),请将 ocelot.json 中的 "ReRoutes" 更改为 "Routes"。
我遇到了同样的问题,然后遇到了这个拉取请求,解释说它已经更改为与新的 Microsoft 反向代理项目 (YARP) 相匹配。他们的文档需要更新。 https://github.com/ThreeMammals/Ocelot/pull/1239