Skip to content

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

Open
@andriysavin

Description

@andriysavin

Is there an existing issue for this?

  • 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:

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-routinginvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions