-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conventional routing with custom templates not working when you have area attributes #7959
Comments
@davidliang2008 From the repro app its not clear where you are trying to generate the links from. Are you doing it from the DashboardController to Products? if so, the ambient value of 'admin' is probably being used. |
No, all product links are public. They're not under The issue is:
Hope I explained it clearly. |
Ah yes, I am able to reproduce the issue. Investigating the cause... |
So seems like the root cause of the issue is change in behavior of the In netcoreapp2.0, the following prints Console.WriteLine(StringComparer.OrdinalIgnoreCase.GetHashCode("")); // here "" can be thought as area="" Since this used to give In netcoreapp2.1, the above code prints a non-zero value which causes a look up miss for action descriptors where they are built with key like area=null and the look value is area="" cc @rynowak @davidliang2008 as a workaround, you can change your route configuration to be like defaults: new { area = (string)null, controller = "products", action = "listByType" } |
FYI @stephentoub in case the behavior change was unintentional. |
You guys are awesome!! |
It's intentional. Randomized string hashing was enabled for IgnoreCase in 2.1. |
Is this a Bug or Feature request?:
Bug
Steps to reproduce (preferably a link to a GitHub repo with a repro project):
https://github.com/davidliang2008/DL.Issues.AspNetCore.Mvc.CustomRouting
Description of the problem:
When you want a more user/SEO friendly URLs on your site, you would set up custom routings to use slugs instead of ids.
And then I have the controller and action setup to handle those requests.
So the following links are expected to call their corresponding actions:
Everything works fine until you add an area! All custom URLs would return 404!
Notes:
[Area("admin")]
is commented out, all custom links would work with the settingnew { area = "", ... }
.[Area("admin")]
on, the only way to get those custom links to work is to removearea = ""
from custom routing setup.Microsoft.AspNetCore.Mvc
2.0.7!Version of
Microsoft.AspNetCore.Mvc
orMicrosoft.AspNetCore.App
orMicrosoft.AspNetCore.All
:V2.1.0
The text was updated successfully, but these errors were encountered: