Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkGenerator generate wrong links across areas #20489

Closed
valeriob opened this issue Apr 3, 2020 · 7 comments
Closed

LinkGenerator generate wrong links across areas #20489

valeriob opened this issue Apr 3, 2020 · 7 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates Status: Resolved
Milestone

Comments

@valeriob
Copy link

valeriob commented Apr 3, 2020

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

@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 3, 2020
@javiercn
Copy link
Member

javiercn commented Apr 3, 2020

@valeriob thanks for contacting us.

I believe this is caused by a difference in how endpoint routing treats ambient values. Check https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2#differences-from-earlier-versions-of-routing for details.

@rynowak to confirm, but I think this is expected.

@valeriob
Copy link
Author

valeriob commented Apr 3, 2020

Ouch, if this is by design it's a very bad news :(
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-3.1#problems-with-route-value-invalidation

So the only way to use netcore3 is to disable EndpointRouting, but what is the path forward ? If you will remove the old behavior before implementing this new feature it will case a lot of pain to a lot of people.
Do you have this feature in the roadmap ? I think that it's very important to be able to have this kind of AmbientValues, for many scenarios !

  • localization
  • multitenant
  • whatever ppl need to have as ambient value

See also
#19395

Thanks

@rynowak
Copy link
Member

rynowak commented Apr 4, 2020

The answer from @javiercn is correct. The best thing for now is to revert to the old routing system. We'll be adding a feature in 5 that allows you to have more control over how ambient values behave.

@valeriob
Copy link
Author

valeriob commented Apr 5, 2020

Hi @rynowak ,
by "more control" can we imply that we'll be able to specify a global ambient parameter in routing with this pattern like before "/CustomValue/{globalAmbientValue}/{controller}/{action}" ?
Thanks for sharing the roadmap, i'll keep a close eye to net5 :D

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Apr 6, 2020
@ghost ghost added the Status: Resolved label Apr 6, 2020
@ghost
Copy link

ghost commented Apr 7, 2020

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Apr 7, 2020
@rynowak rynowak reopened this Apr 7, 2020
@rynowak rynowak removed the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Apr 7, 2020
@rynowak
Copy link
Member

rynowak commented Apr 7, 2020

Yes. That's the plan

@Pilchie
Copy link
Member

Pilchie commented May 11, 2020

Closing resolved issue.

@Pilchie Pilchie closed this as completed May 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 2020
@danroth27 danroth27 changed the title LinkGenerator generate wrong links accross areas LinkGenerator generate wrong links across areas Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants