This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Description
From @anobaka on December 6, 2016 7:20
Minimal repro steps
- Create a sample .net core web application.
- Modify the
app.UseMvc... line to:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "test",
template: "{area?}/{controller=Home}/{action=Index}/{id?}"
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
- Add
TestController and an Index action in it.
- Add
var a = Url.Action("Index", "Test"); in Index Action of HomeController.
- Run app and visit
/.
Expected result
local variable a should be /Test
Actual result
the value of a is /
Further technical details
I checked the source of Routing and found that the raw route values will not be restored after template binder failed binding values. So when the default router was tring to generate url, there was action:Index only left in route values, so it used the default controller Home.
ref:
https://github.com/aspnet/Routing/blob/rel/1.1.0/src/Microsoft.AspNetCore.Routing/Template/TemplateBinder.cs#L238
https://github.com/aspnet/Routing/blob/rel/1.1.0/src/Microsoft.AspNetCore.Routing/Template/TemplateBinder.cs#L279
I think the logic is that all routers should try to bind raw route values to generate url, but not the route values modified by previous router, so the raw route values should be restored after each router binding or routers should use the copy of the raw route values.
Thanks.
Copied from original issue: dotnet/aspnetcore#1860