question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambigous route matches

See original GitHub issue

Describe the bug

These two routes lead to an ambiguous match on Toyota-Corolla-vehicles/2.

    [HttpGet("{make}-{query}-vehicles/{makeId:int}")]
    [HttpGet("{make}-vehicles/{makeId:int}")]

According to my understanding, they shouldn’t as the two parameters are separated by a - which is a valid string literal. As per the docs, the routes match non greedily from right to left by comparing literals. the first route has two literals, the second route has only one literal, so I don’t see why it would be ambiguous when Toyota-Corolla-vehicles/2 contains two literals that match the first route in the form of - and -vehicles

To Reproduce

Add these routes to an action

    [HttpGet("{make}-{query}-vehicles/{makeId:int}")]
    [HttpGet("{make}-vehicles/{makeId:int}")]

Fire a get in the format

Toyota-Corolla-vehicles/2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rynowakcommented, May 13, 2019

You can configure which one of these you want to be considered first with Order. https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-2.2#ordering-attribute-routes

2reactions
huysentruitwcommented, May 7, 2019

I’m not trying to defend the current implementation, the idea you have makes perfectly sense. However, I do think that it would make the route matching code more complex and probably slower (although the slowdown could be limited to figuring out the correct path in case of ambiguity). So let’s wait until someone from the core team joins this conversation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin Shell Raise Ambiguous Routes matched Exception
System.ArgumentException: 'Ambiguous routes matched for: ...' This occures when you register your routes in XAML (in the appshell file) and ...
Read more >
Failed to Navigate Back, Ambiguous routes matched for.... ...
I am building an Xamarin Forms app for iOS and Android. I registered my routes in AppShell.xaml.cs globally like this: ...
Read more >
Ambiguous Matches with React Router - ui.dev
In this post, you'll learn how to handle ambiguous matches with React Router.
Read more >
Resolve Ambiguous Controller Error by routes
Now the time is to resolve the common error "multiple matching controllers were found" raised by the routing system when your application ...
Read more >
React Router - Ambiguous Matches
Explore this online React Router - Ambiguous Matches sandbox and experiment with it yourself using our interactive online playground.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found