Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
892 views
in Technique[技术] by (71.8m points)

c# - 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": []

}]

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)
{
...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...