使用Ocelot(7.0.4)重新路由错误asp.net Core

时间:2018-10-16 05:56:38

标签: c# asp.net-mvc asp.net-core ocelot

    while (inFile.hasNextLine()) {
        input = inFile.nextLine();
        lineCount++;
        altInput = "";
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c >= 'A' && c <= 'Z')
                altInput = altInput + ((char) (c + 32));
            else if (c >= 'a' && c <= 'z')
                altInput = altInput + ((char) (c - 32));
            else if (c >= '0' && c <= '9') {
                switch (c) {
                case '0':
                    altInput += "zero";
                    break;
                case '1':
                    altInput += "one";
                    break;
                case '2':
                    altInput += "two";
                    break;
                case '3':
                    altInput += "three";
                    break;
                case '4':
                    altInput += "four";
                    break;
                case '5':
                    altInput += "five";
                    break;
                case '6':
                    altInput += "six";
                    break;
                case '7':
                    altInput += "seven";
                    break;
                case '8':
                    altInput += "eight";
                    break;
                case '9':
                    altInput += "nine";
                    break;
                }
                if (i < input.length() - 1 && (input.charAt(i + 1) >= '0' && input.charAt(i + 1) <= '9'))
                    altInput += "-";
            } else
                altInput = altInput + input.charAt(i);
        }
        outFile.println(altInput);
        System.out.println(altInput);
    }
    inFile.close();
    outFile.close();

}

在这里,我试图将我的UpstreamPathTemplate从查询字符串重新路由到DownstreamPathTemplate,

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

}]

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

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

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

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

这意味着此处将我的UpstreamPath作为

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

此处缺少参数。

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

1 个答案:

答案 0 :(得分:0)

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