dotnet / dotnet/aspnetcore

IUrlHelper.Action() inexplicably takes callsite action context into account for determining target action.

Open
#52,665 3 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

In a controller action that has an overload with an additional parameter, redirecting from that overloaded implementation to the default action is impossible using `Controller.Url.Action()`.

A small reproduction can be seen in this repository: https://github.com/StringEpsilon/route_bug

Within the `Do(string, Mode)` method, any attempt to create an URL to `Do(string)` will result instead in a link to `Do(string, Mode)`. In this particular scenario that results in an infinite loop of redirects.

### Expected Behavior

The default IUrlHelper implementation should not pull route parameter information from the current ActionContext to distinguish between method overloads on the same controller. In other words the following call should always produce the same URL, regardless of which method makes that call:

```cs
this.Url.Action(nameof(Do), new {templateId = "SomeTemplate"});
// should always equal: /do/SomeTemplate
// but will return: /do/SomeTemplate/ when called from Do(string, Mode)
```

### Steps To Reproduce

See this small reproduction repository: https://github.com/StringEpsilon/route_bug

Build & run the project, then click on the link that is rendered by the "Do" view that says "Do with mode". That will trigger the redirect loop described above.

### Exceptions (if any)

_No response_

### .NET Version

8.0.100

### 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.