所以,我有一个处理某些路由的WebAPI,需要将其余路由传递给这样的向下REST API
前端---> MyWebAPI - > AnotherAPI
任何返回404的请求(或者不是,我对所有与现有路线不匹配的内容感到满意)
我设法使用MapWhen和aspnetcore.Proxy中间件进行代理。但是在任何路由匹配之前执行,所以我不知道请求是否匹配。
app.MapWhen((context) =>
context.Response.StatusCode == 404,
builder =>
builder.RunProxy(new ProxyOptions
{
Scheme = "http",
Host = Configuration.GetValue<string>("APIAddress"),
Port = Configuration.GetValue<string>("APIPort")
}));
有没有办法在路由匹配后执行此操作? 另一种方法是捕捉所有这样的路线:
[Route("{*url}", Order = 999)]
public IActionResult CatchAll()
{
//do the proxying here
}
然后我必须管理正确代理请求的所有细微差别。