조치의 실제 실행을 우회하여 값을 리턴하는 ActionFilterAttribute를 작성할 수 있습니까?실제 조치 실행을 우회하여 값을 리턴하는 조치 필터 속성 작성
3
A
답변
2
당신은 할 수 있습니다 :
1) 어떤 행동에 리디렉션 후 일부 값 반환 :
public class MyFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
/*If something happens*/
if (/*Condition*/)
{
/*You can use Redirect or RedirectToRoute*/
filterContext.HttpContext.Response.Redirect("Redirecto to somewhere");
}
base.OnActionExecuting(filterContext);
}
}
(2)) 요청에 direcly 값을 쓰고 클라이언트에 전송을 끝냅니다.
public class MyFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
/*If something happens*/
if (/*Condition*/)
{
filterContext.HttpContext.Response.Write("some value here");
filterContext.HttpContext.Response.End();
}
base.OnActionExecuting(filterContext);
}
}
6
예, 가능합니다. ActionFilterAttribute
에 OnActionExecuting
을 재정의 할 때 제공되는 필터 컨텍스트의 결과를 설정할 수 있습니다. 소스에서
using System.Web.Mvc;
public sealed class SampleFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Result = new RedirectResult("http://google.com");
}
}
, 당신은 필터 컨텍스트의
Result
속성을 설정하는 흐름을 변경하는 것을 볼 수 있습니다. System.Web.Mvc.ControllerActionInvoker에서
이 같은
internal static ActionExecutedContext InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func<ActionExecutedContext> continuation)
{
filter.OnActionExecuting(preContext);
if (preContext.Result != null)
{
return new ActionExecutedContext(preContext, preContext.ActionDescriptor, true /* canceled */, null /* exception */)
{
Result = preContext.Result
};
}
// other code ommitted
}
관련 문제
- 1. 조치 속성
- 2. 조치 성공시 조치 실행
- 3. WebAPI 용 인증 조치 필터
- 4. 조치
- 5. 조치
- 6. InheritedResources에 대한 성공적인 작성 또는 업데이트 조치 후 조치 실행
- 7. 조치 값을 보내기 : @selector
- 8. 신청서 작성 후 조치 수행
- 9. 조치 호출 호출자
- 10. 조치 결과에 대한 실제 이벤트 수신
- 11. HTML5 검증 - PHP 양식 조치 속성 빈
- 12. MVC 조치
- 13. 대처 조치
- 14. 컨트롤러 조치
- 15. 제출시 조치
- 16. 조치 Heroku가
- 17. Eclipse 플러그인에서 조치 요소의 속성 값을 수정하는 f}
- 18. C# 목록 속성 추가 방법 추가 조치
- 19. Html.ActionLink 조치 낙오자
- 20. 호출 조치 참조
- 21. struts2에서 행 현명한 조치
- 22. 원치 않는 조치
- 23. Infinispan 장애 조치 기능
- 24. 조치 변수의 값 유지?
- 25. Rails에서는/users에 대한 GET이 색인 조치 용이고 RESTful 표준은/users에 대한 POST가 작성 조치 용입니까?
- 26. 테이블에서 값을 채우는 Oracle apex 동적 조치
- 27. 콘텐츠 삭제, 보안 조치
- 28. 비밀 번호에 대한 후속 조치 안드로이드 응용 프로그램의 실행을 보호
- 29. 확률이 p 인 조치 선택
- 30. ZK 오류 단추 조치
인가가없는 경우를 의미합니까? – Fals
@Fals 필수는 아닙니다. – mattalxndr