Using the following routes:
app.UseMvc(routes =>
{
routes.MapAreaRoute(
name: "MyAreaProducts",
areaName:"Products",
template: "Products/{controller=Home}/{action=Index}/{id?}"
);
routes.MapAreaRoute(
name: "MyAreaServices",
areaName: "Services",
template: "Services/{controller=Home}/{action=Index}/{id?}"
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Navigation to https://localhost:5001/Products/Home/About
throws:
An unhandled exception occurred while processing the request.
AmbiguousMatchException: The request matched multiple endpoints. Matches:
MVCareas.Areas.Products.Controllers.HomeController.About (MVCareas)
MVCareas.Controllers.HomeController.About (MVCareas)
Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateSet candidates)
Repo here: Run app and select the Products/Home/About link.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
options.EnableEndpointRouting = false)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
Using .NET Core 2.2.2
dotnet --version
2.2.104
cc @JamesNK
Thanks for logging this.
The issues is already fixed in 3.0. To be decided whether to patch in 2.2. Most likely not because there is a simple work-around in 2.2.
@JamesNK, @mkArtakMSFT did this fix made it to .net core 2.2.3, which has just been released?
It didn't. For 2.2 you should disable endpoint routing. In 3.0 this is fixed.
You need to add area descriptor to controller to make it run. Ex.[Area("Admin")]
I had this problem in Core 3.0. I finally found the solution was to put a route attribute on the action - e.g. [Route("NodeInfo")]. That fixed it
Yeap. I just had same problem.
Solution is Route Attribute
Example ;
[Route("areaName/[controller]")]
public class MyController:ControllerBase{}
Most helpful comment
You need to add area descriptor to controller to make it run. Ex.[Area("Admin")]