簡體   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