码迷,mamicode.com
首页 > Web开发 > 详细

MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获

时间:2014-11-28 14:12:25      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   for   on   

public class BaseController : Controller
    { 
        /// <summary>
        /// Called after the action method is invoked.
        /// </summary>
        /// <param name="filterContext">Information about the current request and action.</param>
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {

            var servicename = string.Empty;

            foreach (var value in filterContext.RequestContext.RouteData.Values) 
            {
                if (value.Key.ToLower() == "controller")  //获取当前的Controller
                {
                    servicename += value.Value.ToString() + "---";
                }
                else if (value.Key.ToLower() == "action")//获取当前的ActionName
                {
                    servicename += value.Value.ToString();
                }
            }
            LogWriter.Debug(servicename);
            base.OnActionExecuted(filterContext);
        } 

        /// <summary>
        /// Called when an unhandled exception occurs in the action.
        /// </summary>
        /// <param name="filterContext">Information about the current request and action.</param>
        protected override void OnException(ExceptionContext filterContext)
        {
            LogWriter.Error(filterContext.Exception.Message, filterContext.Exception); //全局异常捕获输出

            base.OnException(filterContext);
        }

    }  

 

MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获

标签:style   blog   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/liuyunsheng/p/4128181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!