{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/2097","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/2097/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/2097/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/2097/events","html_url":"https://github.com/aspnet/Mvc/issues/2097","id":59313493,"number":2097,"title":"Cannot get controller instance in IExceptionFilter","user":{"login":"aanufriyev","id":557594,"avatar_url":"https://avatars.githubusercontent.com/u/557594?v=3","gravatar_id":"","url":"https://api.github.com/users/aanufriyev","html_url":"https://github.com/aanufriyev","followers_url":"https://api.github.com/users/aanufriyev/followers","following_url":"https://api.github.com/users/aanufriyev/following{/other_user}","gists_url":"https://api.github.com/users/aanufriyev/gists{/gist_id}","starred_url":"https://api.github.com/users/aanufriyev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aanufriyev/subscriptions","organizations_url":"https://api.github.com/users/aanufriyev/orgs","repos_url":"https://api.github.com/users/aanufriyev/repos","events_url":"https://api.github.com/users/aanufriyev/events{/privacy}","received_events_url":"https://api.github.com/users/aanufriyev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-28T00:16:51Z","updated_at":"2015-03-03T19:26:59Z","closed_at":null,"body":"In previous versions there was a way to get controller instance in exception filter like:\r\n<code>var curentController = actionExecutedContext.ActionContext.ControllerContext.Controller;<code> \r\n\r\nIn MVC6 this feature seems to be missing from <code>ExceptionContext</code>. In <code>IActionFilter</code>'s <code>ResultExecutingContext</code> Controller property exists.\r\n\r\nThis stuff is very useful when exception handling requires some sort of knowledge about exception context. For example - exception to status code maps with customization on per controller basis.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/77015773","html_url":"https://github.com/aspnet/Mvc/issues/2097#issuecomment-77015773","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/2097","id":77015773,"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":"2015-03-03T19:26:59Z","updated_at":"2015-03-03T19:26:59Z","body":"Keep in mind that doing it this way works *with* inheritance and scoping, there's no need to duplicate. So the exception mappings on an action include those on:\r\n1). The action directly\r\n2). The controller\r\n3). Inherited from a base controller\r\n4). Registered in startup (options.Filters)\r\n\r\nIf your exception mappings are consistent you can register them all during startup. If you want to treat the same exception differently in different scopes/controllers this supports that."}}