{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/Routing/issues/312","repository_url":"https://api.github.com/repos/aspnet/Routing","labels_url":"https://api.github.com/repos/aspnet/Routing/issues/312/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Routing/issues/312/comments","events_url":"https://api.github.com/repos/aspnet/Routing/issues/312/events","html_url":"https://github.com/aspnet/Routing/issues/312","id":153677809,"number":312,"title":"Optional route constraint not working when before [controller] placeholder","user":{"login":"TsengSR","id":10427430,"avatar_url":"https://avatars.githubusercontent.com/u/10427430?v=3","gravatar_id":"","url":"https://api.github.com/users/TsengSR","html_url":"https://github.com/TsengSR","followers_url":"https://api.github.com/users/TsengSR/followers","following_url":"https://api.github.com/users/TsengSR/following{/other_user}","gists_url":"https://api.github.com/users/TsengSR/gists{/gist_id}","starred_url":"https://api.github.com/users/TsengSR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TsengSR/subscriptions","organizations_url":"https://api.github.com/users/TsengSR/orgs","repos_url":"https://api.github.com/users/TsengSR/repos","events_url":"https://api.github.com/users/TsengSR/events{/privacy}","received_events_url":"https://api.github.com/users/TsengSR/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-08T21:09:35Z","updated_at":"2016-05-08T21:09:35Z","closed_at":null,"body":"I got a bit of little challange getting routes working the way I'd like. Basically, I want to have a locale/culture as part of the url path rather than the currently provided query parameter, cookie or accepted language header.\r\n\r\nSo I made a constraint for it, which is working so far. \r\n\r\n```\r\n    public class LocaleConstraint : IRouteConstraint\r\n    {\r\n        private static readonly Regex LocalePattern = new Regex(@\"^[a-z]{2}(-[a-z]{2,4})?$\", RegexOptions.Compiled | RegexOptions.IgnoreCase);\r\n\r\n        public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection)\r\n        {\r\n            if (!values.ContainsKey(routeKey))\r\n                return false;\r\n\r\n            string locale = values[routeKey] as string;\r\n            if (string.IsNullOrWhiteSpace(locale))\r\n                return false;\r\n\r\n            return LocalePattern.IsMatch(locale);\r\n        }\r\n    }\r\n```\r\n\r\nThen I create an route via attributes on the controller\r\n\r\n```\r\n[Route(\"api/{culture:locale}/[controller]\")]\r\npublic class ExampleController : Controller \r\n{\r\n    ...\r\n}\r\n```\r\n\r\nWorks well so far. But it only works when I access it via `/api/en-US/exampe/` url. `/api/exampe` is not working. I tried `\"api/{culture:locale?}/[controller]\"` and `\"api/{culture:locale=en-US}/[controller]\"`, but none of them matches `/api/example`.\r\n\r\nOf course it works, when I add both routes to the controller.\r\n\r\n```\r\n[Route(\"api/[controller]\")]\r\n[Route(\"api/{culture:locale}/[controller]\")]\r\npublic class ExampleController : Controller \r\n{\r\n    ...\r\n}\r\n```\r\n\r\nWhile this works, it has some nasty side effects. I use Swashbuckle Swagger for API documentation and it will generate all routes double, which is pretty annoying. \r\n\r\nIs there any way to get the optional parameter working on the `culture` url parameter? I can get it, if this doesn't work as a general route defined in Startup.cs (because controller is not know at this time), but when using attribute routing the [controller] is being replaced with the controller name when doing the registrations, so to my understanding optional parameters before the `[controller]` placeholder shouldn't be a problem. \r\n\r\nIs this a bug?"}}