Exemple #1
0
 /// <summary>
 /// 处理后
 /// </summary>
 /// <param name="filterContext"></param>
 protected override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     if (filterContext.Exception != default(Exception))
     {
         if (filterContext.Exception.GetType() == typeof(DomainInfoException))
         {
             var ex = filterContext.Exception as DomainInfoException;
             filterContext.ExceptionHandled = true;
             if (ex.IsLog)
             {
                 SystemLog.Logs.GetLog().WriteErrorLog(ex);
                 result.Succeeded     = false;
                 result.Msg           = ex.Message;
                 filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
             }
             else
             {
                 result.Succeeded     = false;
                 result.Msg           = ex.Message;
                 filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
             }
         }
         else
         {
             //处理controller的异常
             SystemLog.Logs.GetLog().WriteErrorLog(filterContext.Exception);
             filterContext.ExceptionHandled = true;
         }
     }
     else //if (filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.HttpContext.Request.RequestType.ToLower() == "post")
     {
         //filterContext.Result = File(Security.EncryptionResponse(ParameterLoader.LoadResponseJSONStr(result)), "application/octet-stream");
         //var ret = Security.EncryptionResponse(ParameterLoader.LoadResponseJSONStr(result));
         //filterContext.HttpContext.Response.BinaryWrite(ret);
         filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
     }
 }
Exemple #2
0
        /// <summary>
        /// 处理后
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var isAjaxRequest /*是否是ajax异步请求*/ = filterContext.HttpContext.Request.IsAjaxRequest();
            var requestType /*请求类型*/          = filterContext.HttpContext.Request.RequestType.ToLower();

            //如果响应遇到异常
            if (filterContext.Exception != default(Exception))
            {
                //DomainInfoException表示这个是自定义的信息
                if (filterContext.Exception is DomainInfoException)
                {
                    var ex = filterContext.Exception as DomainInfoException;
                    if (ex != null && ex.IsLog)
                    {
                        SystemLog.Logs.GetLog().WriteErrorLog(ex);/*记录日志*/
                        result.Succeeded     = false;
                        result.Msg           = ex.Message;
                        filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
                    }
                    else
                    {
                        result.Succeeded     = false;
                        result.Msg           = ex != null ? ex.Message : "后台执行中出现异常";
                        filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
                    }
                    filterContext.ExceptionHandled = true;
                }
                else
                {
                    //处理controller的异常
                    SystemLog.Logs.GetLog().WriteErrorLog(filterContext.Exception);
                    result.Succeeded               = false;
                    result.Msg                     = filterContext.Exception.Message;
                    filterContext.Result           = Content(ParameterLoader.LoadResponseJSONStr(result));
                    filterContext.ExceptionHandled = true;
                }
            }
            else if (isAjaxRequest && requestType == "post")
            {
                //请求是脚本 ajax POST 的请求
                filterContext.Result = Content(ParameterLoader.LoadResponseJSONStr(result));
            }
            else if (isAjaxRequest && requestType == "get")
            {
                //这里一般是通过easyui的panel或者dialog的get请求请求部分数据的处理
                var controller = filterContext.RequestContext.RouteData.Values["controller"].ToString().ToLower();
                var action     = filterContext.RequestContext.RouteData.Values["action"].ToString().ToLower();

                //排除登录和菜单、首页还有不需要按钮的标识,如果非登录和菜单、首页,
                //你需要载入按钮的话,那么把NeedMenuButton置为true就可以了
                if (controller != "login" && controller != "menu" && controller != "main" && action == "index" || NeedMenuButton)
                {
                    //请求是get请求,一般都是打开某个菜单,获取会话中的用户权限菜单信息
                    var menuinfo = GetSessionInfo(SessionInfo.USER_MENUS /*用户的权限和菜单等信息*/) as UserRoleMenuInfo;

                    if (menuinfo != null)
                    {
                        //找到当前控制器对应的菜单信息
                        var userMenu = menuinfo.AllMenu.Where(m =>
                        {
                            return(m.sUrl.Split(new char[] { '/' }).Last().ToLower() == controller);
                        }).FirstOrDefault();

                        if (userMenu != default(UserMenu))
                        {
                            //添加这个菜单有的btn,这里是会排序的,如果编辑了菜单按钮的排序,刷新就可以了
                            filterContext.Controller.ViewData.Add("btns", userMenu.Buttons.OrderBy(m => m.iOrder).ToList());
                        }
                    }
                }
            }
            else
            {
                //其他方式的请求:暂无处理
            }
        }