{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/1913","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/1913/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/1913/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/1913/events","html_url":"https://github.com/aspnet/Mvc/issues/1913","id":55844640,"number":1913,"title":"Consider changing Attribute Route behavior with areas + ambient values","user":{"login":"rynowak","id":1430011,"avatar_url":"https://avatars.githubusercontent.com/u/1430011?v=3","gravatar_id":"","url":"https://api.github.com/users/rynowak","html_url":"https://github.com/rynowak","followers_url":"https://api.github.com/users/rynowak/followers","following_url":"https://api.github.com/users/rynowak/following{/other_user}","gists_url":"https://api.github.com/users/rynowak/gists{/gist_id}","starred_url":"https://api.github.com/users/rynowak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rynowak/subscriptions","organizations_url":"https://api.github.com/users/rynowak/orgs","repos_url":"https://api.github.com/users/rynowak/repos","events_url":"https://api.github.com/users/rynowak/events{/privacy}","received_events_url":"https://api.github.com/users/rynowak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-29T01:49:56Z","updated_at":"2015-01-29T01:49:56Z","closed_at":null,"body":"Right now, link generation for attribute routes when using areas behaves very similarly to conventional routing. Much like conventional routing, when you have duplicate action and controller names you must either:\r\n\r\n1). Be explicit about route when generating links (always specify the area token)\r\n2). Use order to configure the desired precedence.\r\n\r\nExample follows...\r\n\r\n**The question is.. do we want this behavior to be smarter than conventional routing?** We might be able to implement something good here. There's a small tuning change we could make to this algorithm to make this work as-desired without the need for setting an order.\r\n\r\n\r\nExample: Consider the following conventionally routed controllers:\r\n```\r\nnamespace MvcSample.Web1\r\n{\r\n    [Area(\"A1\")]\r\n    public class RoutingTest : Controller\r\n    {\r\n        public string Action()\r\n        {\r\n            return Url.Action();\r\n        }\r\n    }\r\n}\r\n\r\nnamespace MvcSample.Web2\r\n{\r\n    public class RoutingTest : Controller\r\n    {\r\n        public string Action()\r\n        {\r\n            return Url.Action();\r\n        }\r\n    }\r\n}\r\n```\r\nwith routes\r\n```\r\n                routes.MapRoute(\"areaRoute\", \"{area:exists}/{controller}/{action}\");\r\n                routes.MapRoute(\"controllerActionRoute\", \"{controller}/{action}\",);\r\n```\r\n\r\n\r\nEach of these actions tries to link to itself, using only ambient values. If the routes are ordered as-is, then this will work as expected.\r\n```\r\nhttp://localhost:5001/A1/RoutingTest/Action -> http://localhost:5001/A1/RoutingTest/Action\r\nhttp://localhost:5001/RoutingTest/Action ->      http://localhost:5001/RoutingTest/Action\r\n```\r\n\r\n**However, if you switch the route ordering, then the `controllerActionRoute` is too greedy.**\r\n```\r\nhttp://localhost:5001/A1/RoutingTest/Action -> http://localhost:5001/RoutingTest/Action\r\nhttp://localhost:5001/RoutingTest/Action ->      http://localhost:5001/RoutingTest/Action\r\n```\r\n\r\nThis is an inherent issue in attribute routing. You get the same issue with attribute routes when you have a duplicate action/controller. Order is needed to resolve the problem (if you're relying on ambient values).\r\n\r\nEx:\r\n```\r\nnamespace MvcSample.Web3\r\n{\r\n    [Area(\"A2\")]\r\n    [Route(\"A2/[controller]/[action]\")]\r\n    public class AttributeRoutingTest : Controller\r\n    {\r\n        public string Action()\r\n        {\r\n            return Url.Action();\r\n        }\r\n    }\r\n}\r\n\r\nnamespace MvcSample.Web4\r\n{\r\n    [Route(\"[controller]/[action]\", Order = 1)]\r\n    public class AttributeRoutingTest : Controller\r\n    {\r\n        public string Action()\r\n        {\r\n            return Url.Action();\r\n        }\r\n    }\r\n}\r\n```\r\n"}}