Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints.
ID: dotnet/ambiguous-match
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 8 | active | — | — | — |
Root Cause
AmbiguousMatchException occurs when ASP.NET Core routing cannot determine which endpoint should handle a request because multiple routes match the same URL pattern. Common with attribute routing, overlapping route templates, and controller action overloads. Fix by adding route constraints or making route templates unique.
genericWorkarounds
-
90% success Add route constraints to differentiate ambiguous endpoints
Use route constraints to disambiguate: [HttpGet("{id:int}")] for integer IDs vs [HttpGet("{slug:alpha}")] for string slugs. Common constraints: :int, :guid, :alpha, :regex(). For complex cases, implement IRouteConstraint for custom matching logic -
88% success Use [HttpGet], [HttpPost] method-specific attributes with unique templates
Replace generic [Route] with HTTP method-specific attributes that have distinct templates: [HttpGet("items")] and [HttpGet("items/{id:int}")] instead of two [Route("items")] actions. Ensure each HTTP method + route template combination is unique across all controllers
Dead Ends
Common approaches that don't work:
-
Adding [Route] attributes to every action with fully explicit paths
60% fail
Over-specifying routes creates a maintenance burden and often introduces new ambiguities when combined with controller-level [Route] attributes. The resulting route paths become fragile and hard to reason about
-
Removing [ApiController] attribute to disable automatic model binding and routing behavior
80% fail
Removing [ApiController] disables important features like automatic 400 responses for invalid models, attribute routing requirement, and binding source inference. It does not fix the ambiguous route templates