{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Docs/issues/1795","repository_url":"https://api.github.com/repos/aspnet/Docs","labels_url":"https://api.github.com/repos/aspnet/Docs/issues/1795/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Docs/issues/1795/comments","events_url":"https://api.github.com/repos/aspnet/Docs/issues/1795/events","html_url":"https://github.com/aspnet/Docs/issues/1795","id":171976650,"number":1795,"title":"fundamentals/routing - clarify use of attributes","user":{"login":"vaindil","id":771134,"avatar_url":"https://avatars.githubusercontent.com/u/771134?v=3","gravatar_id":"","url":"https://api.github.com/users/vaindil","html_url":"https://github.com/vaindil","followers_url":"https://api.github.com/users/vaindil/followers","following_url":"https://api.github.com/users/vaindil/following{/other_user}","gists_url":"https://api.github.com/users/vaindil/gists{/gist_id}","starred_url":"https://api.github.com/users/vaindil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vaindil/subscriptions","organizations_url":"https://api.github.com/users/vaindil/orgs","repos_url":"https://api.github.com/users/vaindil/repos","events_url":"https://api.github.com/users/vaindil/events{/privacy}","received_events_url":"https://api.github.com/users/vaindil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"Rick-Anderson","id":3605364,"avatar_url":"https://avatars.githubusercontent.com/u/3605364?v=3","gravatar_id":"","url":"https://api.github.com/users/Rick-Anderson","html_url":"https://github.com/Rick-Anderson","followers_url":"https://api.github.com/users/Rick-Anderson/followers","following_url":"https://api.github.com/users/Rick-Anderson/following{/other_user}","gists_url":"https://api.github.com/users/Rick-Anderson/gists{/gist_id}","starred_url":"https://api.github.com/users/Rick-Anderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rick-Anderson/subscriptions","organizations_url":"https://api.github.com/users/Rick-Anderson/orgs","repos_url":"https://api.github.com/users/Rick-Anderson/repos","events_url":"https://api.github.com/users/Rick-Anderson/events{/privacy}","received_events_url":"https://api.github.com/users/Rick-Anderson/received_events","type":"User","site_admin":false},"assignees":[{"login":"Rick-Anderson","id":3605364,"avatar_url":"https://avatars.githubusercontent.com/u/3605364?v=3","gravatar_id":"","url":"https://api.github.com/users/Rick-Anderson","html_url":"https://github.com/Rick-Anderson","followers_url":"https://api.github.com/users/Rick-Anderson/followers","following_url":"https://api.github.com/users/Rick-Anderson/following{/other_user}","gists_url":"https://api.github.com/users/Rick-Anderson/gists{/gist_id}","starred_url":"https://api.github.com/users/Rick-Anderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rick-Anderson/subscriptions","organizations_url":"https://api.github.com/users/Rick-Anderson/orgs","repos_url":"https://api.github.com/users/Rick-Anderson/repos","events_url":"https://api.github.com/users/Rick-Anderson/events{/privacy}","received_events_url":"https://api.github.com/users/Rick-Anderson/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2016-08-18T19:06:16Z","updated_at":"2016-08-19T02:31:34Z","closed_at":null,"body":"As discussed in [this SO question](https://stackoverflow.com/questions/39008789), routing in MVC only functions if one of these three conditions is met. All routes otherwise return a 404.\r\n\r\n * BOTH the class AND action have a `[Route]` attribute.\r\n * NEITHER the class NOR the action has a `[Route]` attribute.\r\n * The `[action]` parameter is set inside the class route: `[Route(\"[controller]/[action]\")]`.\r\n\r\nI think this should be clarified in the docs, as it took me and others a little while to figure it out.\r\n\r\nThe examples below assume a request to `/values/getfirst` for simplicity. The app was registered using `app.UseMvcWithDefaultRoute()`.\r\n\r\nThis works because no route attributes are set:\r\n\r\n```csharp\r\npublic class ValuesController\r\n{\r\n    [HttpGet]\r\n    public IActionResult GetFirst()\r\n    {\r\n        return Ok();\r\n    }\r\n}\r\n```\r\n\r\nThis also works because both have route attributes:\r\n\r\n```csharp\r\n[Route(\"[controller]\")]\r\npublic class ValuesController\r\n{\r\n    [Route(\"getfirst\")]\r\n    [HttpGet]\r\n    public IActionResult GetFirst()\r\n    {\r\n        return Ok();\r\n    }\r\n}\r\n```\r\n\r\nThis does not work because only the class has the attribute:\r\n\r\n```csharp\r\n[Route(\"[controller]\")]\r\npublic class ValuesController\r\n{\r\n    [HttpGet]\r\n    public IActionResult GetFirst()\r\n    {\r\n        return Ok();\r\n    }\r\n}\r\n```\r\n\r\nThis does work because the class route attribute specifies `[action]`:\r\n\r\n```csharp\r\n[Route(\"[controller]/[action]\")]\r\npublic class ValuesController\r\n{\r\n    [HttpGet]\r\n    public IActionResult GetFirst()\r\n    {\r\n        return Ok();\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/aspnet/Docs/issues/comments/240912210","html_url":"https://github.com/aspnet/Docs/issues/1795#issuecomment-240912210","issue_url":"https://api.github.com/repos/aspnet/Docs/issues/1795","id":240912210,"user":{"login":"Rick-Anderson","id":3605364,"avatar_url":"https://avatars.githubusercontent.com/u/3605364?v=3","gravatar_id":"","url":"https://api.github.com/users/Rick-Anderson","html_url":"https://github.com/Rick-Anderson","followers_url":"https://api.github.com/users/Rick-Anderson/followers","following_url":"https://api.github.com/users/Rick-Anderson/following{/other_user}","gists_url":"https://api.github.com/users/Rick-Anderson/gists{/gist_id}","starred_url":"https://api.github.com/users/Rick-Anderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rick-Anderson/subscriptions","organizations_url":"https://api.github.com/users/Rick-Anderson/orgs","repos_url":"https://api.github.com/users/Rick-Anderson/repos","events_url":"https://api.github.com/users/Rick-Anderson/events{/privacy}","received_events_url":"https://api.github.com/users/Rick-Anderson/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T02:31:34Z","updated_at":"2016-08-19T02:31:34Z","body":"So it looks like the rule is:\r\n If you add the  [Route] attribute to a  controller, you indicate that you want to start building a new route; any routes set in startup don't apply. Therefore each action requires a route attribute."}}
{"actor":{"display_login":"Rick-Anderson"}}