This is .net core 6.0 IIS app, porting from framework. RedirectToRoute 302 URL doesn’t include the action if the action is default.
Program.cs:
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}/{id?}",
defaults: new { controller = "Controller1", action = "Index" });
In Controller1Controller:
if (someCondition) { RedirectToAction("Index", "Controller2"); }
The Index action in Controller2 is called. But the 302 redirect 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
.
If I go:
if (someCondition) { RedirectToAction("SomeOtherAction", "Controller2"); }
The action is included in the route.
This is different than framework behavior. Is this a bug in .net core, or is something wrong with my expectation here.