kobake / AspNetCore.RouteAnalyzer

MIT License
88 stars 26 forks source link

Show Area name as part of the route path to avoid confusion #15

Open thiagomajesk opened 6 years ago

thiagomajesk commented 6 years ago

If you have an controller inside a area like this:

[Area("Products")]
public class HomeController : Controller
{
    [HttpGet("[controller]/[action]/{id}")]
    public IActionResult Index(int id) => Ok();

    public IActionResult Show(int id) => Ok();    
}

You'll have routes mapped for /Home/Index and /Products/Home/Show.

¹{ Area = "Products", Path: "/Home/Index" },
 { Area = "Products", Path: "/Home/Show" }

¹ This is missleading since the route is not acessible through /Products/Home/Index due to attribute override.

The solution for me would be to include area into the route path. It makes sense to me because this already happens if you put an attribute route like: HttpGet("[area]/[controller]/[action]") on top of an action.