Re-routing Error asp.net Core with Ocelot (7.0.4)

妖精的绣舞 提交于 2019-12-18 05:29:06

问题


"ReRoutes": [
{
  "DownstreamPathTemplate": "/api/Agent/GetPagedAgents?page={page}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "agent.api",
      "Port": 80
    }
  ],
  "UpstreamPathTemplate": "/api/account/user/list/GetPagedAgents?page={page}",
  "UpstreamHttpMethod": []

}]

Here I am trying to Re-route my UpstreamPathTemplate to DownstreamPathTemplate from a query string,

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

this is my query string am sending to my account management service for re-route to my agent service using ocelot.

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

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

that means here it's taking my UpstreamPath as

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

missing the parameter here.

any help will be appreciated. Thank you


回答1:


Did you try to add [FromQuery] attribute?

public IActionResult Get([FromQuery] string page, [FromQuery] string pageSize, [FromQuery] string filter, [FromQuery]string sortBy)
{
...
}

or create a simple model

public class Request
{
   public string Page { get; set; }
   public string PageSize { get; set; }
   public string Filter { get; set; }
   public string SortBy { get; set; }
}

and use it like

public IActionResult Get([FromQuery] Request request)
{
...
}


来源:https://stackoverflow.com/questions/52828750/re-routing-error-asp-net-core-with-ocelot-7-0-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!