dotnet / dotnet/aspnetcore

AmbiguousMatchException when using "{controller}.aspx" route template

Open
#48,813 3 comments 0 reactions 0 assignees View on GitHub
area-mvc feature-routing investigate
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`:

![image](https://github.com/dotnet/aspnetcore/assets/12996633/ca601ee3-9482-4d25-abf3-67b0b303d99c)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.