dotnet / dotnet/aspnetcore

RedirectToRoute with default action doesn't include action in URL.

Open
#56,117 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

This is a .net core 6.0 IIS app, porting from framework. RedirectToRoute 302 URL doesn't include the action if the action is default, and this is different than Framework.

Program.cs:
``` c#
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}/{id?}",
defaults: new { controller = "Controller1", action = "Index" });
```

In Controller1Contoller:
``` c#
if (someCondition) { RedirectToAction("Index", "Controller2"); }
```

The index action in Controller2 is called, but the 302 redirect URL is: `http://PathToMyApp/Controller2`. Not `http://PathToMyApp/Controller2/Index` or even `http://PathToMyApp/Controller2/`.

This is an issue with routing, because `http://PathToMyApp/Controller2`, any AJAX call send from client will go to `http://PathToMyApp/action` and not `http://PathToMyApp/Controller2/action`. Resulting in 404.

If I go: `{ RedirectToAction("SomeOtherAction", "Controller2"); }`, the action is included in the route.

### Expected Behavior

I would expect a redirect URL to include the action, even if the action is default. This is how it worked in the framework app.

### Steps To Reproduce

https://github.com/AaronDavidNewman/RedirectApp

### Exceptions (if any)

_No response_

### .NET Version

8.0.202

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