使用Ocelot(7.0.4)重新路由错误asp.net Core [英] Re-routing Error asp.net Core with Ocelot (7.0.4)
问题描述
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/Agent/GetPagedAgents?page={page}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "agent.api",
"Port": 80
}
],
"UpstreamPathTemplate": "/api/account/user/list/GetPagedAgents?page={page}",
"UpstreamHttpMethod": []
}]
在这里,我试图将我的UpstreamPathTemplate从查询字符串重新路由到DownstreamPathTemplate,
Here I am trying to Re-route my UpstreamPathTemplate to DownstreamPathTemplate from a query string,
"http://accountmanagement/api/account/user/list/GetPagedAgents?page=1"
这是我的查询字符串,正在发送到我的帐户管理服务,以便使用ocelot重新路由到我的代理服务.
this is my query string am sending to my account management service for re-route to my agent service using ocelot.
这是我在代理服务中的Controller方法,用于接收重新路由的路径
This is my Controller method in agent service for receiving re-routed path
[HttpGet]
[Route("GetPagedAgents")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public IActionResult Get(string page, string pageSize, string filter,
string sortBy)
{
var Result = _agentServices.GetAll(Convert.ToInt32(page),
Convert.ToInt32(pageSize),filter,sortBy);
return Ok(Result);
}
但是它不起作用.在我的OUTPUT窗口中,它的显示消息:无法找到路径的下游路由:/api/account/user/list/GetPagedAgents,动词:GET
But it's not working. In my OUTPUT window its showing message: Unable to find downstream route for path: /api/account/user/list/GetPagedAgents, verb: GET
这意味着这里将我的UpstreamPath作为
that means here it's taking my UpstreamPath as
Upstream url path is /api/account/user/list/GetPagedAgents
此处缺少参数.
任何帮助将不胜感激.谢谢
any help will be appreciated. Thank you
推荐答案
您是否尝试添加[FromQuery]
属性?
public IActionResult Get([FromQuery] string page, [FromQuery] string pageSize, [FromQuery] string filter, [FromQuery]string sortBy)
{
...
}
或创建一个简单的模型
public class Request
{
public string Page { get; set; }
public string PageSize { get; set; }
public string Filter { get; set; }
public string SortBy { get; set; }
}
并像使用它
public IActionResult Get([FromQuery] Request request)
{
...
}
这篇关于使用Ocelot(7.0.4)重新路由错误asp.net Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!