This two action routing works fine in .netcore 2.1
but after migrate to .netcore 6
shown error: AmbiguousMatchException: The request matched multiple endpoints
I followed https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-6.0 but could not resolved the issue.
//Just for two route /content/game & /content/software
[Route("/content/{pageId=game}")]
[Route("/content/{pageId=software}")]
public IActionResult Index1(string pageId, [FromQuery] int page=1)
{}
//For all other url(/content/*)
[Route("/content/{package}")]
public IActionResult Index2(string package)
{}
CodePudding user response:
You use regex to achieve it, Please refer:
//only match /context/game or /content/software
[Route("/content/{pageId:regex(^(game|software)$)}")]
[HttpGet]
public int Index1(string pageId, [FromQuery] int page = 1)
{
return 2;
}
//For all other url(/content/*)
[Route("/content/{package:regex(^(?!.*(game|software)).*$)}")]
[HttpGet]
public int Index2(string package)
{
return 1;
}