Skip to content

LinkGenerator generate wrong links across areas #20489

@valeriob

Description

@valeriob

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 :

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

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

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

image

AspNetCore3RoutingBug.zip

Metadata

Metadata

Assignees

Labels

Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions