dotnet / dotnet/aspnetcore

RedirectToAction() makes the link to HttpPost action instead of GET

Open
#23,089 6 comments 0 reactions 0 assignees View on GitHub
affected-most area-mvc bug feature-routing severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Hi !
For GET and POST methods with the same action names,

```
Microsoft.AspNetCore.Routing.DefaultLinkGenerator[105]
[2020-06-18 14:05:13.651]: Link generation succeeded for endpoints

```
generates lincorrect link that in my case eventually led to "too many redirects". (as far as I have investigated, it happens because the link is generated to HttpPost method instead of HttpGet when they both have the same name)

The issue happens for route patterns such as [Route("[controller]/{parameter}/action}")]

and does not happen for the route patterns like [Route("[controller]/action/{parameter}")]

Just to mention, HttpPost action has route pattern [Route("[controller]/action")] (parameter passes in ViewModel)

I have managed with the issue having renamed POST methods so that their names don't match with GET methods.

As for me, such behavior seems incorrect (as well as that RedirectToAction considers POST methods at all to generate links) or I might have lack of knowledge about ASP.Net core MVC routing.

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.