我有一个 Ocelot 网关配置如下:
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/api/{version}/{everything}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 3010
}
],
"UpstreamPathTemplate": "/serviceName/api/{version}/{everything}",
"UpstreamHttpMethod": [ "POST", "PATCH", "PUT", "GET", "DELETE" ]
}
}
我有以下控制器
[Produces("application/json")]
[Route("api/v1/[controller]")]
[ApiController]
public class NameController : ControllerBase
{
[HttpPost()]
public async Task<IActionResult> Create([FromForm]Request request, CancellationToken cancellationToken)
{
// create something..
return CreatedAtRoute("Get", new { id }, string.Empty);
}
[HttpGet("{id}", Name = "Get")]
public async Task<IActionResult> Get([FromRoute] string id, CancellationToken cancellationToken)
{
// return something
}
}
我希望我的 Location 标题是{domain}/serviceName/api/v1/Name/{id}
,但是它正在返回{domain}/api/v1/Name/{id}
。
任何人都知道如何使用 CreatedAtRoute 进行 URL 重写,好吗?