简体   繁体   English

如何在Webapi .net Core 2.2中配置自定义终结点

[英]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

You can view my blog here 你可以在这里查看我的博客

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.

相关问题 如何在 .NET Core 2.2 WebApi 和 Azure AD 2.0 中配置 Swagger? - How to Configure Swagger in .NET Core 2.2 WebApi and Azure AD 2.0? 如何在.Net core 2.2中为自定义属性配置AutoMapper? - How to configure AutoMapper in .Net core 2.2 for custom properties? 如何在.NET Core 2.2中为SignalR配置JsonOptions? - How to configure JsonOptions for SignalR in .NET Core 2.2? 如何使用.Net Core WebApi将Azure CDN与前端SPA和Azure WebApp配置到相同的自定义域? - How to configure Azure CDN with front-end SPA and Azure WebApp with .Net Core WebApi to same custom domain? .NET CORE 2.2 身份 + WebAPI 基本身份验证 - .NET CORE 2.2 Identity + Basic Auth for WebAPI 如何在 .net core 2.2 webapi 中访问 GitLab CI CD 环境变量 - How can I access GitLab CI CD Environment variables in .net core 2.2 webapi 如何使用正则表达式匹配路由部分中的部分 url? WebAPI .NET 核心 2.2 - How to use regular expression to match part of url in route part? WebAPI .NET core 2.2 在 WebApi 中的 Asp Core 2.2 中创建自定义返回错误验证 - Create Custom Return Error Validate in Asp Core 2.2 in WebApi 不允许使用ASP.NET Core 2.2 WebAPI 405方法 - ASP.NET Core 2.2 WebAPI 405 Method Not Allowed Net Core 2.2 MVC WebApi中的JWT“自我”身份验证 - JWT “self” authentication in Net Core 2.2 MVC WebApi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM