dotnet / dotnet/aspnetcore

MapDynamicControllerRoute doesn't consider ActionMethodSelectorAttribute

Open
#19,101 5 comments 1 reaction 0 assignees View on GitHub
affected-very-few area-mvc bug feature-routing investigate severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

The following code will produce an exception:
AmbiguousMatchException: The request matched multiple endpoints.
- App.Web.Controllers.TestController.ButtonClick1 (App.Web)
- App.Web.Controllers.TestController.ButtonClick2 (App.Web)
```
public class FormConstraintAttribute : ActionMethodSelectorAttribute
{
...
}

public async Task Form()
{
return View();
}

[HttpPost, ActionName(nameof(Form), FormConstraint("button", "1")]
public async Task ButtonClick1()
{
return View(nameof(Form));
}

[HttpPost, ActionName(nameof(Form), FormConstraint("button", "2")]
public async Task ButtonClick2()
{
return View(nameof(Form));
}
```
Setup:
```
// This will throw AmbiguousMatchException:
routeBuilder.MapDynamicControllerRoute("{**path}");
// This works:
routeBuilder.MapControllerRoute(routeName: "Form", pattern: "form", defaults: new { controller = "Test", action = "Form" });
```
With the "old" IRouter this was possible.

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.