"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);
}
但它不起作用。在我的OUTPUT窗口中显示消息:无法找到路径的下游路由:/ 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)
{
...
}