0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ony19161
  • 73
  • 8
  • 1
    try without the `api` in the url – Igor Apr 21 '22 at 19:20
  • You may read this section for [more details](https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0#attribute-routing-for-rest-apis) – Tiny Wang Apr 22 '22 at 01:48

1 Answers1

1

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.