2012-11-09 2 views

답변

0

당신은 당신의 자신의 속성이

public class LogExceptionAttribute : ActionFilterAttribute 
    { 
     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
       base.OnActionExecuting(filterContext); 
     } 

     public override void OnActionExecuted(ActionExecutedContext filterContext) 
     { 
       //here you can inspect filterContext for exceptions 
       base.OnActionExecuted(filterContext); 
     } 

     public override void OnResultExecuting(ResultExecutingContext filterContext) 
     { 
      base.OnResultExecuting(filterContext); 
     } 

     public override void OnResultExecuted(ResultExecutedContext filterContext) 
     { 
      base.OnResultExecuted(filterContext); 
     } 
    } 

ActionFilterAttribute

에서 파생 쓰기 그리고 액션/컨트롤러의 속성을 넣어 또는 Global.asax에, 글로벌 필터로 ApplicationStart()에 등록 할 수 있습니다.

예 : 예외를 로그인하거나 다른 일을 할 수있게된다

[LogException] 
     public ActionResult Index() 
     { 
      throw new Exception(); 
      return View(); 
     } 

enter image description here

.

+0

그냥 처리되지 않은 예외 (이 일을 순서대로 예외를 rethrow합니다) 작동합니다. – raulgomis