-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Undocumented route value invalidation when route values are not specified in route pattern #31602
Comments
Thanks for contacting us. |
Sure thing, thanks for that. Note I am having difficulties coming up with a workaround when the current URL is in an area eg. if the current URL matches the following route:
Any URLs generated for routes outside of the current area don't pass through the culture ambient route value and I can't figure out how to use a similar hack as above to avoid this. Also pinging #16960 as initially I thought it was related to that bug. Looks like others have thought the same. |
I've had a similar problem and the most simple solution which worked for me was to keep the old routing (app.UseMvc) and use endpoint routing for other stuff like endpoints.MapReverseProxy().
and the service registration:
I'm not sure if there are any drawbacks regarding this solution but for now it looks like everything works without rewriting of every action URL generation call... |
@tdamir Thanks for this suggestion; it seems to work for a netcore2.1 project that I've inherited and am updating to Net5.0. My symptom was empty href strings everywhere when using "asp-page" anchor tag, whereby the original site was utilising ambient values for various userId, documentId etc to build the URLs. Your solution seems like the cleanest one I've found; I do not wish to implement hacky helper classes or manually change hundreds of anchor tags - I've got real work to do. |
Hi, is this related ? #31476 |
@ajbeaven We've also run into this when moving from ASP.NET Core 2.1 to 5.0. You're saying this:
However, I think you're running into the concept of "required values". If I understand correctly, if the required values "controller" or "action" do not appear inside the pattern/template, they are assumed to be "to the left" of everything else. I.e., when either controller or action changes, all ambient values are invalidated (as they are viewed to be to the right). I think the docs even highlight your specific issue in the section titled Problems with route value invalidation:
Altogether, I find the concept of "required values" hard to understand, not very intuitive. |
I'm moving my question over to #31476. |
Indeed @fschmied ! This kind of feature is the very reason to use a framework like aspnet. |
@fschmied looks like you're right. Looking forward to global ambient values being a thing. Edit: oops, sorry for the close/reopen - misclick! |
Describe the bug
I believe the changes made in .NET Core 2.2(?) with ambient route value invalidation do not rightly consider how routes are generated when a route pattern is specified that does not contain controller or action route values.
Consider the following routes:
If the current page is
/ru
, the URL generated withUrl.Action("Index", "TestA")
will differ between versions:/ru/test-a-with-fancy-route
/test-a-with-fancy-route
From what I gather from the URL generation process documentation, a route value is invalidated if in the pattern it appears to the right of a route value that is changed. The pattern above does not specify controller or action, so I would expect that the
culture
ambient route value would not be invalidated as it is in the latest versions of .NET.To Reproduce
Here's a repro showing the behaviour change from .NET Core 2.1 to .NET Core 3.1.
Clone the repro above, run the two projects side-by-side and follow the instructions below on each:
/ru
(thereby making culture an ambient route value)Workaround
I have found a hacky(?) work around for my particular case, but if there are better options, I'm all ears:
By replacing the route at the top with something like that, I continue to restrict that route to the one specific controller action, but also force the route invalidation rules to work as they are described in the documentation above.
Further technical details
See here
.NET Core 3.1
dotnet --info
:Visual studio 16.9.2
The text was updated successfully, but these errors were encountered: