protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (IsInstalled()) { var route = filterContext.RouteData; string allowUrl = Core.Helper.WebHelper.GetRawUrl().ToLower(); string area = string.Empty; if (route != null) { area = (route.DataTokens["area"] == null ? "" : route.DataTokens["area"].ToString().ToLower()); } //PC端手动输入移动端地址+wap端+微信端 if (area == "mobile" || visitorTerminalInfo.Terminal == EnumVisitorTerminal.WeiXin || visitorTerminalInfo.Terminal == EnumVisitorTerminal.Moblie || visitorTerminalInfo.Terminal == EnumVisitorTerminal.PAD) { if (!allowUrl.Contains("/shopregisterjump/") && !allowUrl.Contains("/shopregister/") && !allowUrl.Contains("/topic/detail/") && !allowUrl.Contains("/bigwheel/") && !allowUrl.Contains("/scratchcard/") && !allowUrl.Contains("/payment/"))//商家入驻,专题页,大转盘,刮刮卡,移动端支付控制器(小程序支付后异步处理需权限) { if (!SiteSettings.IsOpenH5) { var erroView = "~/Areas/Mobile/Views/Shared/Authorize.cshtml"; var result = new ViewResult() { ViewName = erroView }; filterContext.Result = result; filterContext.HttpContext.Response.StatusCode = 200; ServiceApplication.DisposeService(filterContext); return; } } } if (visitorTerminalInfo.Terminal == EnumVisitorTerminal.PC && area == "web" && (!allowUrl.Contains("login")) && (!allowUrl.Contains("seleradmin")) && (!allowUrl.Contains("findpassword"))) //不应处理商家后台,登录,找回密码 { if (!allowUrl.Contains("/pay/")) //支付不需验证 { if (!SiteSettings.IsOpenPC) { var erroView = "~/Areas/Web/Views/Shared/Authorize.cshtml"; var result = new ViewResult() { ViewName = erroView }; filterContext.Result = result; filterContext.HttpContext.Response.StatusCode = 200; ServiceApplication.DisposeService(filterContext); return; } } } } //跳转移动端 JumpMobileUrl(filterContext); base.OnActionExecuting(filterContext); }
protected override void OnResultExecuted(ResultExecutedContext filterContext) { ServiceApplication.DisposeService(filterContext); }
protected override void OnException(ExceptionContext filterContext) { var pra = filterContext.Controller.ControllerContext.HttpContext.Request; Exception innerEx = GerInnerException(filterContext.Exception); string msg = innerEx.Message; if (!(innerEx is HimallException) && !(innerEx is PluginException)) { var controllerName = filterContext.RouteData.Values["controller"].ToString(); var actionName = filterContext.RouteData.Values["action"].ToString(); var areaName = filterContext.RouteData.DataTokens["area"]; var Id = filterContext.RouteData.DataTokens["id"]; var erroMsg = string.Format("页面未捕获的异常:Area:{0},Controller:{1},Action:{2},id:{3}", areaName, controllerName, actionName, Id); erroMsg += "Get:" + pra.QueryString + "post:" + pra.Form.ToString(); if (filterContext.Exception.GetType().FullName == "System.Data.Entity.Validation.DbEntityValidationException") { try { var errorMessages = GetEntityValidationErrorMessage(filterContext.Exception); if (errorMessages.Count > 0) { erroMsg += "\r\n" + string.Join("\r\n", errorMessages); } } catch { } } Log.Error(erroMsg, filterContext.Exception); msg = "系统发生错误,请重试,如果再次发生错误,请联系客服!"; } if (WebHelper.IsAjax()) { Result result = new Result(); result.success = false; result.msg = msg; result.status = -9999; filterContext.Result = Json(result); //将状态码更新为200,否则在Web.config中配置了CustomerError后,Ajax会返回500错误导致页面不能正确显示错误信息 filterContext.HttpContext.Response.StatusCode = 200; filterContext.ExceptionHandled = true; ServiceApplication.DisposeService(filterContext); } else { // var erroView = "Error"; if (innerEx is Himall404) { erroView = "404"; } //if (IsMobileTerminal) // erroView = "~/Areas/Mobile/Templates/Default/Views/Shared/Error.cshtml"; //#if !DEBUG var result = new ViewResult() { ViewName = erroView }; result.ViewData["erroMsg"] = msg; filterContext.Result = result; // base.OnResultExecuting(filterContext.Result); //将状态码更新为200,否则在Web.config中配置了CustomerError后,Ajax会返回500错误导致页面不能正确显示错误信息 filterContext.HttpContext.Response.StatusCode = 200; filterContext.ExceptionHandled = true; ServiceApplication.DisposeService(filterContext); //#endif } if (innerEx is HttpRequestValidationException) { if (WebHelper.IsAjax()) { Result result = new Result(); result.msg = "您提交了非法字符!"; filterContext.Result = Json(result); } else { var result = new ContentResult(); result.Content = "<script src='/Scripts/jquery-1.11.1.min.js'></script>"; result.Content += "<script src='/Scripts/jquery.artDialog.js'></script>"; result.Content += "<script src='/Scripts/artDialog.iframeTools.js'></script>"; result.Content += "<link href='/Content/artdialog.css' rel='stylesheet' />"; result.Content += "<link href='/Content/bootstrap.min.css' rel='stylesheet' />"; result.Content += "<script>$(function(){$.dialog.errorTips('您提交了非法字符!',function(){window.history.back(-1)},2);});</script>"; filterContext.Result = result; } filterContext.HttpContext.Response.StatusCode = 200; filterContext.ExceptionHandled = true; ServiceApplication.DisposeService(filterContext); } }