[英]How to configure custom endpoint in webapi .net core 2.2
如何在像/api/v1/{product}/{service}
这样的webapi .netcore 2.2上配置自定义终结点?
You can use aspnet-api-versioning 您可以使用aspnet-api-versioning
Here is the sample 这是样本
Install-Package Microsoft.AspNetCore.Mvc.Versioning -Version 2.2.0
Then in Startup.cs 然后在Startup.cs中
public void ConfigureServices(IServiceCollection services)
{
services.AddApiVersioning(options =>
{
options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0);
});
}
And finally register in the controller 最后在控制器中注册
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
public class AccountController:Controller
It works well when I use below api action and test with url like https://localhost:5001/api/v1/hello/world
. 当我使用下面的api操作并使用https://localhost:5001/api/v1/hello/world
类的URL进行测试时,它工作得很好。
Api action: api动作:
[HttpGet("/api/v1/{service}/{product}")]
public IActionResult Payment([FromRoute(Name = "service")]string service, [FromRoute(Name = "product")]string product)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.