Hi,
i've been using this route rules for years (Mvc, AspNetcore <=2.2) now i'm porting a webapp to aspnetcore3.1.
"Area1/{tenant}/{controller=Home}/{action=Index}/{id?}"
"Area2/{tenant}/{controller=Home}/{action=Index}/{id?}"
Generating links for those routes 3.1 it's not working in some scenario :
- if i'm on a page not contained in any area /Home/Index, the link generation works ok
Url.Action("Index", "Home", new { Area = "Area1", tenant = "t1" }) = "/Area1/t1" Ok
Url.Action("Index", "Home", new { Area = "Area2", tenant = "t1" }) = "/Area2/t2" Ok
-
if i follow the first link /Area1/t1/Home/Index
Url.Action("Index", "Home", new { Area = "Area1", }) = "/Area1/t1" Ok
Url.Action("Index", "Home", new { Area = "Area2", }) = "/?Area=Area2" Wrong
-
viceversa if i follow the second link to /Area2/t1/Home/Index
Url.Action("Index", "Home", new { Area = "Area1", }) = "/?Area=Area1" Wrong
Url.Action("Index", "Home", new { Area = "Area2", }) = "/Area2/t1" Ok
This feature is required because to build efficiently a multi-tenant application, you just need to select the tenant once, and it will be passed to the whole application automatically (and have been for many many years).
It looks like that the method GetValues in src\Http\Routing\src\Template\TemplateBinder.cs disables copying AmbientValues if the area is different :( That's very unfortunate.
Attached is the repro, Navigate to link Area1 and Area2 to see the generation failing.

AspNetCore3RoutingBug.zip
Hi,
i've been using this route rules for years (Mvc, AspNetcore <=2.2) now i'm porting a webapp to aspnetcore3.1.
"Area1/{tenant}/{controller=Home}/{action=Index}/{id?}"
"Area2/{tenant}/{controller=Home}/{action=Index}/{id?}"
Generating links for those routes 3.1 it's not working in some scenario :
Url.Action("Index", "Home", new { Area = "Area1", tenant = "t1" }) = "/Area1/t1" Ok
Url.Action("Index", "Home", new { Area = "Area2", tenant = "t1" }) = "/Area2/t2" Ok
if i follow the first link /Area1/t1/Home/Index
Url.Action("Index", "Home", new { Area = "Area1", }) = "/Area1/t1" Ok
Url.Action("Index", "Home", new { Area = "Area2", }) = "/?Area=Area2" Wrong
viceversa if i follow the second link to /Area2/t1/Home/Index
Url.Action("Index", "Home", new { Area = "Area1", }) = "/?Area=Area1" Wrong
Url.Action("Index", "Home", new { Area = "Area2", }) = "/Area2/t1" Ok
This feature is required because to build efficiently a multi-tenant application, you just need to select the tenant once, and it will be passed to the whole application automatically (and have been for many many years).
It looks like that the method GetValues in src\Http\Routing\src\Template\TemplateBinder.cs disables copying AmbientValues if the area is different :( That's very unfortunate.
Attached is the repro, Navigate to link Area1 and Area2 to see the generation failing.
AspNetCore3RoutingBug.zip