AmbiguousMatchException when using "{controller}.aspx" route template
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
I have an MVC app with these conrollers among others:
- LoginController
- VaildateElectronicSignatureController
- ValidateLoginController
Each of them has an action method with the same signature: `IActionResult ValidateLogin()`.
It also has the following route mapping:
```csharp
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}.aspx/{action=Index}/{id?}");
```
Note that the only difference from the default route template is the ".aspx" suffix after "{controller=Home}".
Now, if I navigate to URI "/Login.aspx/ValidateLogin" with this app, I'm getting an `AmbiguousMatchException`:

Here, the ambiguity is between the aforementioned conrollers. This looks like absolute nonsense to me, as the {controller} token should receive the "Login" value, and then controller classes with LoginController name should be looked for. However, `VaildateElectronicSignatureController`, for example, has nothing from the captured controller name at all. It looks like matching is done only by action name, so all controllers with that action method do match.
If I remove the ".aspx" suffix from the routing pattern ("{controller=Home}/{action=Index}/{id?}") and the URI ("/Login/ValidateLogin") the error disappears.
I'm attaching a basic app to reproduce the error.
### Expected Behavior
The `{controller=Home}.aspx/{action=Index}/{id?}` route template should work similarly to default `{controller=Home}/{action=Index}/{id?}` and cause no abiguity with controllers which don't even match the name.
### Steps To Reproduce
https://github.com/andriysavin/bugreports/tree/main/RouteTemplateWithAspxBug
### Exceptions (if any)
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:
WebApplication4.Controllers.LoginController.ValidateLogin (WebApplication4)
WebApplication4.Controllers.VaildateElectronicSignatureController.ValidateLogin (WebApplication4)
WebApplication4.Controllers.ValidateLoginController.ValidateLogin (WebApplication4)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
### .NET Version
7.0.302
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.