ASP.NET MVC ActionFilter의 연속을 중지하십시오
-
20-09-2019 - |
문제
액션에 대해 두 개의 커스텀 액션 필터가 있습니다.
ActionFilters의 첫 번째에는 조건이 충족되지 않으면 리디렉션이 수행됩니다 (클래식 인증). 그리고 다른 조건이 충족되지 않으면 리디렉션이 수행됩니다 (역할 점검).
그러나 첫 번째 액션 필터가 충족되지 않으면 두 번째 액션 필터를 계속하고 싶지 않습니다. 이 작업을 수행하는 방법?
해결책
Setting the filterContext.Result
property to any non-null value will stop execution of later filters. So if your first filter sets filterContext.Result = new RedirectResult(...)
, the second filter and action method will never be run. This is how the built-in [Authorization]
filter works.
제휴하지 않습니다 StackOverflow