ASP.NET Core multi attribute routing

175 views Asked by At

In my ASP.NET Core Web API application, I have declared a route with multiple attributes like following

[HttpGet]
[Route("{tenantId?}/user/getsettings/{id?}")]

When I made a request from swagger, the server is returning 404 not found.

http://localhost:5163/api/1/user/getsettings/2

Is this possible with .NET Core?

1

There are 1 answers

0
Onurkan Bakırcı On

Because your url actually not contains api. You can call url by using http://localhost:5163/1/user/getsettings/2. If you want to add api to your url you can add attribute to controller class by using [Route("api/v{version:apiVersion}/[controller]")].

Tip: You can achive same config with only one HttpGet("{tenantId?}/user/getsettings/{id?}") attribute.