{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Docs/issues/61","repository_url":"https://api.github.com/repos/aspnet/Docs","labels_url":"https://api.github.com/repos/aspnet/Docs/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Docs/issues/61/comments","events_url":"https://api.github.com/repos/aspnet/Docs/issues/61/events","html_url":"https://github.com/aspnet/Docs/issues/61","id":68977420,"number":61,"title":"Routing","user":{"login":"danroth27","id":1874516,"avatar_url":"https://avatars.githubusercontent.com/u/1874516?v=3","gravatar_id":"","url":"https://api.github.com/users/danroth27","html_url":"https://github.com/danroth27","followers_url":"https://api.github.com/users/danroth27/followers","following_url":"https://api.github.com/users/danroth27/following{/other_user}","gists_url":"https://api.github.com/users/danroth27/gists{/gist_id}","starred_url":"https://api.github.com/users/danroth27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danroth27/subscriptions","organizations_url":"https://api.github.com/users/danroth27/orgs","repos_url":"https://api.github.com/users/danroth27/repos","events_url":"https://api.github.com/users/danroth27/events{/privacy}","received_events_url":"https://api.github.com/users/danroth27/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/Docs/labels/2%20-%20Working","name":"2 - Working","color":"CCCCCC"},{"url":"https://api.github.com/repos/aspnet/Docs/labels/aspnet","name":"aspnet","color":"5319e7"},{"url":"https://api.github.com/repos/aspnet/Docs/labels/P0","name":"P0","color":"e11d21"},{"url":"https://api.github.com/repos/aspnet/Docs/labels/topic","name":"topic","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"ardalis","id":782127,"avatar_url":"https://avatars.githubusercontent.com/u/782127?v=3","gravatar_id":"","url":"https://api.github.com/users/ardalis","html_url":"https://github.com/ardalis","followers_url":"https://api.github.com/users/ardalis/followers","following_url":"https://api.github.com/users/ardalis/following{/other_user}","gists_url":"https://api.github.com/users/ardalis/gists{/gist_id}","starred_url":"https://api.github.com/users/ardalis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardalis/subscriptions","organizations_url":"https://api.github.com/users/ardalis/orgs","repos_url":"https://api.github.com/users/ardalis/repos","events_url":"https://api.github.com/users/ardalis/events{/privacy}","received_events_url":"https://api.github.com/users/ardalis/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/aspnet/Docs/milestones/5","html_url":"https://github.com/aspnet/Docs/milestones/1.0.0-rc2","labels_url":"https://api.github.com/repos/aspnet/Docs/milestones/5/labels","id":1443065,"number":5,"title":"1.0.0-rc2","description":"","creator":{"login":"danroth27","id":1874516,"avatar_url":"https://avatars.githubusercontent.com/u/1874516?v=3","gravatar_id":"","url":"https://api.github.com/users/danroth27","html_url":"https://github.com/danroth27","followers_url":"https://api.github.com/users/danroth27/followers","following_url":"https://api.github.com/users/danroth27/following{/other_user}","gists_url":"https://api.github.com/users/danroth27/gists{/gist_id}","starred_url":"https://api.github.com/users/danroth27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danroth27/subscriptions","organizations_url":"https://api.github.com/users/danroth27/orgs","repos_url":"https://api.github.com/users/danroth27/repos","events_url":"https://api.github.com/users/danroth27/events{/privacy}","received_events_url":"https://api.github.com/users/danroth27/received_events","type":"User","site_admin":false},"open_issues":94,"closed_issues":71,"state":"open","created_at":"2015-12-03T22:04:46Z","updated_at":"2016-03-07T21:25:02Z","due_on":null,"closed_at":null},"comments":14,"created_at":"2015-04-16T17:57:58Z","updated_at":"2016-03-07T23:35:28Z","closed_at":null,"body":"ASP.NET 5->Fundamentals->Routing\r\n- Middleware\r\n  - Maps a request to an `IRouteHandler`\r\n  - The `IRouteHandler` returns a `RequestDelegate` or null\r\n    - Example: is there a matching MVC action\r\n  - If null, then routing continues\r\n  - If no route handler can handle the request then the middleware calls next\r\n- Configuration\r\n  - Create RouteBuilder\r\n- Code sample to reference: https://github.com/aspnet/Routing/blob/master/samples/RoutingSample.Web/Startup.cs\r\n- Template routes\r\n  - Ex: `{controller=Home}/{action=Index}/{id?}`\r\n  - Stuff with curly braces defines a route value that will get bound\r\n  - Stuff with an `=` defines a default value. If the path segment is not present then the default value is added to the route values\r\n  - `?` defines an optional value\r\n  - `:` to add inline constraints\r\n    - Constraints can have parameters denoted by parens\r\n    - Ex: int, bool, etc. See https://github.com/aspnet/Routing/blob/master/src/Microsoft.AspNet.Routing/RouteOptions.cs#L41\r\n    - You can chain stuff. Ex `{id:int:range(0,100)}`\r\n    - If the string doesn't match an inline constraint then its treated as a regex (ex match one of three values `{value:foo|bar|baz}`)\r\n  - Prefix route parameter with `*` to bind to the rest of the URI. Ex `/blog/{*slug}`\r\n  - Route templates need to be unambiguous. Ex this doesn't work: `{id?}/{foo}`\r\n  - Complex segments can contain text and parameters. Ex `{mm}-{dd}-{yyyy}`\r\n    - Special complex segment can have an optional file extension (i.e. the dot is special because it is optional too). Ex `/files/{filename}.{ext?}`\r\n- MapRoute extension methods\r\n  - Convenience methods for adding routes to the `RouteBuilder` via the `Route` class\r\n  - https://github.com/aspnet/Routing/blob/master/src/Microsoft.AspNet.Routing/RouteBuilderExtensions.cs#L76\r\n  - You can add additional route constraints using anonymous obj\r\n    - Property values should generally be `IRouteConstraint` implementations\r\n    - Built-in constraints: HTTP verb, regex, etc.\r\n    - If the property value is a string it's treated as a regex constraint\r\n  - Get merged with inline constraints in the template\r\n- Default values\r\n  - Get merged with the defaults in the template, but conflicts cause errors\r\n- Data tokens\r\n  - User defined data bag that gets carried along if the route matches\r\n- Link generation\r\n  - Give routing a set of route values and optionally a route name to produce a URL\r\n  - Current route values of the current request are considered ambient values for link generation\r\n    - Ex When on the About action of the Home controller to link to the Index page you don't need to specify the controller route value.\r\n  - Ambient values that don't match a parameter are ignored\r\n  - Ambient values are ignored when a value explicitly provided overrides it going from left to right in the URL\r\n  - Values the are explicitly provided that don't match anything go into the query string\r\n  - If a route has default values that don't match a parameter and that value is explicitly provided it must match the default value.\r\n\r\n<!---\r\n@huboard:{\"order\":374.8125,\"milestone_order\":61,\"custom_state\":\"\"}\r\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Docs/issues/comments/193507768","html_url":"https://github.com/aspnet/Docs/issues/61#issuecomment-193507768","issue_url":"https://api.github.com/repos/aspnet/Docs/issues/61","id":193507768,"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},"created_at":"2016-03-07T23:35:28Z","updated_at":"2016-03-07T23:35:28Z","body":"Here's the example:\r\n```\r\nroutes.MapRoute(\"blog_route\", \"blog/{*slug}\", defaults: new { controller = \"Blog\", action = \"ReadPost\" });\r\n```\r\n\r\nThis will only generate a link when the matching values for controller and action are provided."}}