繁体   English   中英

使用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,

"http://accountmanagement/api/account/user/list/GetPagedAgents?page=1"

这是我的查询字符串,正在发送到我的帐户管理服务,以便使用ocelot重新路由到我的代理服务。

这是代理服务中我的Controller方法,用于接收重新路由的路径

    [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);
    }

但这不起作用。 在我的输出窗口中,其显示消息:无法找到路径的下游路由:/ api / account / user / list / GetPagedAgents,动词:GET

这意味着这里将我的UpstreamPath作为

 Upstream url path is /api/account/user/list/GetPagedAgents

此处缺少参数。

任何帮助将不胜感激。 谢谢

您是否尝试添加[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)
{
...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM