{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/Docs/pulls/comments/55109158","id":55109158,"diff_hunk":"@@ -1,10 +1,272 @@\n-.. include:: /../common/stub-topic.txt\n+Routing\n+=======\n+By `Steve Smith`_\n \n-.. _routing-index:\n+Routing middleware is used to map requests to route handlers. Routes are configured when the application starts up, and can define values that will be passed as parameters to route handlers. Routing functionality is also responsible generating links that correspond to routes in ASP.NET apps.\n \n-|stub-icon| Routing\n-===================\n+Sections:\n+\t- `Routing Middleware`_\n+\t- `Configuring Routing`_\n+\t- `Template Routes`_\n+\t- `Link Generation`_\n+\n+`View sample files <https://github.com/aspnet/Docs/tree/1.0.0-rc1/aspnet/fundamentals/routing/sample>`_\n+\n+Routing Middleware\n+------------------\n+The routing :doc:`middleware` uses *routes* to map requests to an ``IRouteHandler`` service. The ``IRouteHandler`` service returns a ``RequestDelegate``, or ``null``. If it returns a delegate, that delegate is invoked; otherwise, routing continues. If no route handler is found for a request, then the middleware calls *next* (and the next middleware in the request pipeline is invoked).\n+\n+.. TODO in RC2 Middleware later in the request pipeline can access route data using extensions methods on ``HttpContext``. \n+\n+To use routing, add it to the **dependencies** in ``project.json``:\n+\n+.. literalinclude:: routing/sample/RoutingSample/project.json\n+  :linenos:\n+  :dedent: 2\n+  :language: javascript\n+  :lines: 6-12\n+  :emphasize-lines: 4\n+  \n+Add routing to ``ConfigureServices`` in ``Startup.cs``:\n+\n+.. literalinclude:: routing/sample/RoutingSample/Startup.cs\n+  :linenos:\n+  :dedent: 8\n+  :language: c#\n+  :lines: 16-19\n+  :emphasize-lines: 3\n+\n+\n+Configuring Routing\n+-------------------\n+Routing is enabled in the ``Configure`` method in the ``Startup`` class. Create an instance of `RouteBuilder <https://github.com/aspnet/Routing/blob/1.0.0-rc1/src/Microsoft.AspNet.Routing/RouteBuilder.cs>`_. You can optionally set the ``ServiceProvider`` and/or ``DefaultHandler`` properties, in order to make them available as you build routes.\n+\n+.. literalinclude:: routing/sample/RoutingSample/Startup.cs\n+  :linenos:\n+  :dedent: 8\n+  :language: c#\n+  :lines: 22-35\n+  :emphasize-lines: 7-8,10-13\n+  \n+You can see on the last line above how ``ApplicationServices`` is used to access the ``IInlineConstraingResolver`` dependency; if this were done from a ``RouteBuilder`` extension method, access to the services would be done through the ``ServiceProvider`` property.\n+\n+Once you've finished adding routes to the ``RouteBuilder`` instance, call ``UseRouter`` and pass it the result of the ``RouteBuilder.Build`` method (demonstrated below).\n+\n+.. tip:: If you are only configuring a single route, you can simply call ``app.UseRouter`` and pass in the ``IRouter`` instance you wish to use, bypassing the need to use a ``RouteBuilder``.\n+\n+The route configured abovve will only match requests of the form \"hello/{name}\" where `name` is constrained to be alphabetical. Requests that match this will be handled by a custom ``IRouter`` implementation, ``HelloRouter``.\n+\n+.. literalinclude:: routing/sample/RoutingSample/HelloRouter.cs\n+  :linenos:\n+  :language: c#\n+\n+``HelloRouter`` checks to see if ``RouteData`` includes a value for the key ``name``. If not, it immediately returns without handling the request. Otherwise, the request is handled (by writing out \"Hi {name}!\") and the ``RouteContext`` is updated to note that the request was handled. This prevents additional routes from handling the request.\n+\n+This route was configured to use an inline constraint (see below), signified by the \":alpha\" in the route template for the name route value. This constraint limits which requests this route will handle, in this case to alphabetical values for ``name``. Thus, a request for \"/hello/steve\" will be handled, but a request to \"/hello/123\" will not (instead, the request will pass through to the \"Hello World!\" request delegate).\n+\n+Template Routes\n+---------------\n+The most common way to define routes is using ``TemplateRoute`` and route template strings. In a typical MVC app, you might use a default template route with a string like this one: \n+\n+.. image:: /fundamentals/routing/_static/default-mvc-routetemplate.png\n+\n+Tokens within curly braces (``{ }``) define `route value` placeholders which will be bound if the route is matched. You can define more than one route value placeholder in a route segment, but they must be separated by a literal value. For example \"{controller=Home}{action=Index}\" would not be a valid route, since there is no literal value between ``{controller}`` and ``{action}``. These route value placeholders must have a name, and may have additional attributes specified.\n+\n+The following table demonstrates the available route value placeholder options and `route value constraints <https://github.com/aspnet/Routing/blob/1.0.0-rc1/src/Microsoft.AspNet.Routing/RouteOptions.cs>`_.\n+\n+.. list-table:: Route Template Values\n+\t:header-rows: 1\n+\n+\t* - Route Template\n+\t  - Example Matching URL\n+\t  - Notes\n+\t* - hello\n+\t  - /hello\n+\t  - Will only match the single path '/hello'\n+\t* - {Page=Home}\n+\t  - /\n+\t  - Will match and set ``Page`` to ``Home``.\n+\t* - {Page=Home}\n+\t  - /Contact\n+\t  - Will match and set ``Page`` to ``Contact``\n+\t* - {controller}/{action}/{id?}\n+\t  - /Products/List\n+\t  - Will map to ``Products`` controller and ``List`` method; Since ``id`` was not supplied in the URL, it's ignored.\n+\t* - {controller}/{action}/{id?}\n+\t  - /Products/Details/123\n+\t  - Will map to ``Products`` controller and ``List`` method, with ``id`` set to ``123``.\n+\t* - {controller=Home}/{action=Index}/{id?}\n+\t  - /\n+\t  - Will map to ``Home`` controller and ``Index`` method; ``id`` is ignored.\n+\n+Adding a colon ``:`` after the name allows additional constraints to be set on a route value placeholder.\n+\n+.. list-table:: Route Constraints","path":"aspnet/fundamentals/routing.rst","position":108,"original_position":108,"commit_id":"42d13d28364c5c7898486e4fb57a469a2e860ebc","original_commit_id":"42d13d28364c5c7898486e4fb57a469a2e860ebc","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},"body":"> Route Constraints\r\n\r\nInline Route Constraints.\r\n\r\nAlso add a label so that this table can be easily referenced.","created_at":"2016-03-05T00:35:08Z","updated_at":"2016-03-05T00:35:08Z","html_url":"https://github.com/aspnet/Docs/pull/1037#discussion_r55109158","pull_request_url":"https://api.github.com/repos/aspnet/Docs/pulls/1037","_links":{"self":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/comments/55109158"},"html":{"href":"https://github.com/aspnet/Docs/pull/1037#discussion_r55109158"},"pull_request":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/1037"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/Docs/pulls/1037","id":61316059,"html_url":"https://github.com/aspnet/Docs/pull/1037","diff_url":"https://github.com/aspnet/Docs/pull/1037.diff","patch_url":"https://github.com/aspnet/Docs/pull/1037.patch","issue_url":"https://api.github.com/repos/aspnet/Docs/issues/1037","number":1037,"state":"open","locked":false,"title":"Routing","user":{"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},"body":"Please review @rynowak \r\nNot sure about last sentence, which was taken from our initial discussion - help me clarify it please.","created_at":"2016-03-01T22:02:05Z","updated_at":"2016-03-05T00:35:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a85f9c814f7d9825964c08b76520a0e270be014","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/Docs/pulls/1037/commits","review_comments_url":"https://api.github.com/repos/aspnet/Docs/pulls/1037/comments","review_comment_url":"https://api.github.com/repos/aspnet/Docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/Docs/issues/1037/comments","statuses_url":"https://api.github.com/repos/aspnet/Docs/statuses/42d13d28364c5c7898486e4fb57a469a2e860ebc","head":{"label":"aspnet:ardalis/routing","ref":"ardalis/routing","sha":"42d13d28364c5c7898486e4fb57a469a2e860ebc","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":28239455,"name":"Docs","full_name":"aspnet/Docs","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Docs","description":"Documentation for ASP.NET 5","fork":false,"url":"https://api.github.com/repos/aspnet/Docs","forks_url":"https://api.github.com/repos/aspnet/Docs/forks","keys_url":"https://api.github.com/repos/aspnet/Docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Docs/teams","hooks_url":"https://api.github.com/repos/aspnet/Docs/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Docs/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Docs/events","assignees_url":"https://api.github.com/repos/aspnet/Docs/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Docs/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Docs/tags","blobs_url":"https://api.github.com/repos/aspnet/Docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Docs/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Docs/languages","stargazers_url":"https://api.github.com/repos/aspnet/Docs/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Docs/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Docs/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Docs/subscription","commits_url":"https://api.github.com/repos/aspnet/Docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Docs/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Docs/merges","archive_url":"https://api.github.com/repos/aspnet/Docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Docs/downloads","issues_url":"https://api.github.com/repos/aspnet/Docs/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Docs/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Docs/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Docs/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Docs/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/Docs/deployments","created_at":"2014-12-19T17:38:02Z","updated_at":"2016-03-04T15:50:07Z","pushed_at":"2016-03-04T17:55:06Z","git_url":"git://github.com/aspnet/Docs.git","ssh_url":"git@github.com:aspnet/Docs.git","clone_url":"https://github.com/aspnet/Docs.git","svn_url":"https://github.com/aspnet/Docs","homepage":null,"size":41612,"stargazers_count":407,"watchers_count":407,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":656,"mirror_url":null,"open_issues_count":153,"forks":656,"open_issues":153,"watchers":407,"default_branch":"master"}},"base":{"label":"aspnet:master","ref":"master","sha":"76ed88e6a11f535f21ec324fefa9154710d9707a","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":28239455,"name":"Docs","full_name":"aspnet/Docs","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/Docs","description":"Documentation for ASP.NET 5","fork":false,"url":"https://api.github.com/repos/aspnet/Docs","forks_url":"https://api.github.com/repos/aspnet/Docs/forks","keys_url":"https://api.github.com/repos/aspnet/Docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/Docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/Docs/teams","hooks_url":"https://api.github.com/repos/aspnet/Docs/hooks","issue_events_url":"https://api.github.com/repos/aspnet/Docs/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/Docs/events","assignees_url":"https://api.github.com/repos/aspnet/Docs/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/Docs/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/Docs/tags","blobs_url":"https://api.github.com/repos/aspnet/Docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/Docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/Docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/Docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/Docs/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/Docs/languages","stargazers_url":"https://api.github.com/repos/aspnet/Docs/stargazers","contributors_url":"https://api.github.com/repos/aspnet/Docs/contributors","subscribers_url":"https://api.github.com/repos/aspnet/Docs/subscribers","subscription_url":"https://api.github.com/repos/aspnet/Docs/subscription","commits_url":"https://api.github.com/repos/aspnet/Docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/Docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/Docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/Docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/Docs/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/Docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/Docs/merges","archive_url":"https://api.github.com/repos/aspnet/Docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/Docs/downloads","issues_url":"https://api.github.com/repos/aspnet/Docs/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/Docs/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/Docs/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/Docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/Docs/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/Docs/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/Docs/deployments","created_at":"2014-12-19T17:38:02Z","updated_at":"2016-03-04T15:50:07Z","pushed_at":"2016-03-04T17:55:06Z","git_url":"git://github.com/aspnet/Docs.git","ssh_url":"git@github.com:aspnet/Docs.git","clone_url":"https://github.com/aspnet/Docs.git","svn_url":"https://github.com/aspnet/Docs","homepage":null,"size":41612,"stargazers_count":407,"watchers_count":407,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":656,"mirror_url":null,"open_issues_count":153,"forks":656,"open_issues":153,"watchers":407,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/1037"},"html":{"href":"https://github.com/aspnet/Docs/pull/1037"},"issue":{"href":"https://api.github.com/repos/aspnet/Docs/issues/1037"},"comments":{"href":"https://api.github.com/repos/aspnet/Docs/issues/1037/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/1037/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/Docs/pulls/1037/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/Docs/statuses/42d13d28364c5c7898486e4fb57a469a2e860ebc"}}}}