Adding an explicit action route to ASP.NET Web API Controller

后端 未结 2 944
情深已故
情深已故 2021-02-19 00:14

I have an ASP.NET Web API project with an ApiController that provides a User endpoint with the following actions:

GET /api/User
POST /a         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-19 01:18

    If you are using Web API 2, I would suggest to use attribute routing which makes the experience easier for scenarios like these.

    You can continue using the default conventional route for majority of your scenarios, but can use attribute routing in places where you are required to, like in your current scenario.

    Following sample demonstrates a similar scenario:

    http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/WebApiAttributeRoutingSample/WebApiAttributeRoutingSample/Controllers/Api/CustomersController.cs

提交回复
热议问题