zoukankan      html  css  js  c++  java
  • MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获

    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);
            }
    
        }  
  • 相关阅读:
    例程详解
    js对数组中有相似属性对象进行合并
    javaScript放大镜特效
    css改变图标颜色
    js自定义日历
    vuecli4.0配置公共scss样式文件
    iframe根据子页面的内容来设置高度
    iframe父子页面交互
    artTemplate模板自定义函数
    javascript数组的增删改和查询
  • 原文地址:https://www.cnblogs.com/liuyunsheng/p/4128181.html
Copyright © 2011-2022 走看看