阅读背景:

Asp.Net MVC3(三)-MvcApp实现全局异常捕获

来源:互联网 

定义异常捕获类:

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class ExceptionAttribute : FilterAttribute, IExceptionFilter
    {
        public virtual void OnException(ExceptionContext filterContext)
        {
            string message = string.Format("消息类型:{0}<br>消息内容:{1}<br>引发异常的方法:{2}<br>引发异常源:{3}"
                , filterContext.Exception.GetType().Name
                , filterContext.Exception.Message
                 , filterContext.Exception.TargetSite
                 , filterContext.Exception.Source + filterContext.Exception.StackTrace
                 );
            
            //记录日志
            WriteLog.WriteInfo(message);

            //抛出异常信息
            filterContext.Controller.TempData["ExceptionAttributeMessages"] = message;

            //转向
            filterContext.ExceptionHandled = true;
            filterContext.Result = new RedirectResult(Globals.ApplicationDirectory + "/Error/ErrorDetail/");
        }
    }
[AttributeUsage(AttributeTargets



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: