开发者

ASP.NET MVC OnActionExecuted ActionFilter

I trying to check if an exception has been raised by an action with the filterContext.Exception below:

 public class Test : ActionFilterAttribute
    [...]   
    public override void OnActionExecuted(ActionExecutedContext filterContext)
            {
                if (filterContext.Exception != null)
                {
                     continue;
                }
            }

in controller:

        [Test]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Login(Usuarios usuario)
        {
            try
            {
             throw new Exception();
            }
           catch
           {

           }

         }

The filterContext.Exception is always null.I can't catch this inf开发者_StackOverflowormation here.

Any ideias?


That's because the exception never escapes the action method since it gets caught as soon as you throw it. I'm surprised that your code compiles since you don't have a return statement. Anyway, try this action method:

[Test] 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Login(Usuarios usuario) 
{ 
     throw new Exception(); 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜