-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Url.RouteUrl broken after upgrading to asp.net 3.0 endpoint routing #12794
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
Comments
Thanks for contacting us, @dotnetshadow. |
This was a bug in 2.0-2.2 attribute routing that's been fixed. Ambient route values (like @Url.RouteUrl("GetFooByName", new { slug = ... }) This change makes attribute routes and conventional routes behave consistently. |
@rynowak Thank you for getting back to me much appreciated. Is there a section where I can read about this bug?
I'm a little confused about that statement. To me I'm generating an action from a controller that has an ambient value. If the values are on the url and I call The confusing part for me I guess is, that the In my example So in a layout page situation if I want access to the slug I will have to grab it from |
Right, so pages (pre-endpoint-routing) have a bug where route values will be reused across different pages when they wouldn't be for controllers. So if you have This is confusing because you will get different link generation behaviour based on how you got to the current page, and what it's route parameter names are.
The decision process about how we decide which route values to re-use (ambient values) is unfortunately one of the most complex features of ASP.NET Core. It's hard to answer a question like that because the details matter quite a lot.
Ambient values are a feature that exist to try and make your life more convenient when you want to reuse values - unfortunately saying when you want to is a pretty imprecise statement. If you're explicit about what values to pass, that will always win. The easiest way to think about this is that ambient values are reused when you link to the same thing. So if you link from a page back to itself, ambient values are reused. If you link from a page to another page, they will not be reused.
Right. The issue is that we won't reuse the value for
Yes. That will fix it. In general it's not a good idea in general to rely on ambient values inside a layout page. Your layout can be used from lots of different places in the app, so it's likely that the ambient value won't work. |
@rynowak Thank you so much for a thorough explanation. I feel like I understand better now. |
It's discussed here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2#differences-from-earlier-versions-of-routing if you think there's something specific we should add, I'm happy to add it. |
Thank you so much, I must of missed that section |
We just posted this on stackoverflow in case anybody is interested: https://stackoverflow.com/questions/58183201/url-routeurl-is-blank-in-asp-net-core-3-0 From the MSFT documentation, we have not been able to derive how to solve this problem. |
Describe the bug
Upgraded an application from asp.net core 2.2 to 3.0 preview7
On my razor page I used to create the following:
Issue
But since upgrading to asp.net core 3.0 the
getFoo
in 2.2 -
/area/slug/controller/foo
n 3.0 -
blank
<----- ????Using Endpoints - DOESN'T WORK
Using AddMvc - WORKS
I even noticed that my links no longer work correctly since the update
<a class="btn btn-sm btn-outline-info" asp-route="BarRoute" asp-route-option="foo">
The route-option value isn't on the generated url
It seems that I can't use the new use.Endpoint
Expected behavior
in 2.2 -
/area/slug/controller/foo
in 3.0 -
/area/slug/controller/foo
This is a similar issue reported here:
#11320
#11635
The text was updated successfully, but these errors were encountered: