The problems with combining attribute routes in ASP.NET Core
Hello everyone!
Currently I am developing an api with using of ASP.NET Core. Two days ago I notices that my route didn't combine (I am using route attributes).
So, I was writing something like in the code block below.
[Route("users")]
public class UserController : Controller
{
[Route("/{userId}/email")]
public async Task UpdateEmail(int userId, [FromBody]UpdateEmailRequest request)
{
...
}
}
And for the controller and the routes I've got /{userId}/email not users/{userId}/email.
The problem was in the / before the child route.
So, the solution is
[Route("users")]
public class UserController : Controller
{
[Route("{userId}/email")]
public async Task UpdateEmail(int userId, [FromBody]UpdateEmailRequest request)
{
...
}
}