2015-09-04 50 views
0

如果我在控制器中拋出一個未處理的異常,filterContext - > HTTPContext - > Response始終返回200-OK。從ActionFilterAttribute中檢索響應HTTP狀態代碼

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     throw new Exception("some error"); 
     return View(); 
    } 
} 

我如何檢索來自filterContext在ActionFilterAttribute的實際情況,或可以嗎?

public class LogAttribute : ActionFilterAttribute 
{ 
    public override void OnActionExecuted(ActionExecutedContext filterContext) 
    { 
     base.OnActionExecuted(filterContext); 
    } 
} 

回答

0
filterContext.Response?.StatusCode.ToString() ?? "<null>" 

應該給你你在找什麼。

0

更好的選擇是檢查Exception字段。如果你只需要知道是否有一個未處理的異常上升...

相關問題