C# ASP.NET Web API 2控制器中的反向代理?
我试图在我的Web Api控制器中设置一个反向代理,以便 可以过滤请求vía URI并将其发送到各自的 命运 到目前为止,我在Node.js+Express中有一个反向代理,如下所示,我正在尝试将其迁移到WebApi控制器:C# ASP.NET Web API 2控制器中的反向代理?,c#,proxy,asp.net-web-api2,handler,C#,Proxy,Asp.net Web Api2,Handler,我试图在我的Web Api控制器中设置一个反向代理,以便 可以过滤请求vía URI并将其发送到各自的 命运 到目前为止,我在Node.js+Express中有一个反向代理,如下所示,我正在尝试将其迁移到WebApi控制器: var serverOne = 'http://localhost:8080/geoserver/TRAC/wms?'; var serverTwo = 'https://iden.com/ogc/wms?'; var serverThree = 'https://insp
var serverOne = 'http://localhost:8080/geoserver/TRAC/wms?';
var serverTwo = 'https://iden.com/ogc/wms?';
var serverThree = 'https://inspi.com/services/CP/wfs';
app.all('/geoserver', function (req, res) {
apiProxy.web(req, res, {target: serverOne});
});
app.all('/idena', function (req, res) {
apiProxy.web(req, res, {
changeOrigin: true,
target: serverTwo
});
});
app.all('/inspire', function (req, res) {
apiProxy.web(req, res, {
changeOrigin: true,
target: serverThree
});
});
这就是我想要实现的目标:
- 如果我收到
请求,请将其重新发送到localhost:65000/geoserver
serverOne
- 如果我收到一个
请求,请将其重新发送到localhost:65000/idena
serverTwo
- 如果我收到一个
请求,请将其重新发送到localhost:65000/inspire
serverThree
直接在WebAPI控制器中是不可能的,但通过向项目中添加ASP.NET处理程序,可以很容易地完成此操作 然后创建前面提到的反向代理