void IExceptionFilter.OnException(ExceptionContext filterContext)
        {
            ILog   log           = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            bool   isAjaxRequest = filterContext.RequestContext.HttpContext.Request.IsAjaxRequest();
            string controller    = (string)filterContext.RouteData.Values["controller"];
            string action        = (string)filterContext.RouteData.Values["action"];


            MessageBoxModel messageBox = new MessageBoxModel();

            messageBox.No      = Guid.NewGuid().ToString();
            messageBox.Type    = MessageBoxTip.Exception;
            messageBox.Title   = "I'm sorry,Access error";
            messageBox.Content = "<a href=\"javascript:void(0)\" onclick=\"window.top.location.href='" + ManagerUtils.GetHomePage() + "'\">Go Home</a>";

            if (ManagerUtils.CanViewErrorStackTrace())
            {
                messageBox.ErrorStackTrace = CommonUtils.ToHtml(filterContext.Exception.Message + "\r\n" + filterContext.Exception.StackTrace);
            }


            //判断是否异步调用
            if (isAjaxRequest)
            {
                CustomJsonResult jsonResult = new CustomJsonResult(ResultType.Exception, messageBox.No, messageBox.Title, messageBox);
                jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                filterContext.Result           = jsonResult;
                filterContext.Result.ExecuteResult(filterContext);
                filterContext.HttpContext.Response.End();
            }
            else
            {
                string masterName = "_LayoutHome";
                if (filterContext.HttpContext.Request.QueryString["dialogtitle"] != null)
                {
                    masterName = "_Layout";
                }


                filterContext.Result = new ViewResult {
                    ViewName = "MessageBox", MasterName = masterName, ViewData = new ViewDataDictionary {
                        Model = messageBox
                    }
                };
            }


            filterContext.ExceptionHandled = true;
            log.Error("An exception error occurred [number:" + messageBox.No + "]", filterContext.Exception);
        }
Beispiel #2
0
        public static IHtmlString Render(SiteMapNode currNode)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<ul class=\"breadcrumb\">");
            if (currNode == null || currNode.ParentNode == null)
            {
                sb.Append("<li><a href=\"" + ManagerUtils.GetHomePage() + "\" class=\"root\"> &nbsp; </a></li><li><span class=\"site\">" + ManagerBreadcrumb.HomeTite + "</span></li>");
                return(new MvcHtmlString(sb.ToString()));
            }
            else
            {
                var         parents = new List <string>();
                SiteMapNode parent  = currNode.ParentNode;
                while (parent != null)
                {
                    string calssName = "site";
                    string title     = parent.Title;
                    if (parent.Title == ManagerBreadcrumb.HomeTite)
                    {
                        calssName = "root";
                        title     = "&nbsp;";
                    }
                    string html = "<li><a href=\"" + parent.Url + "\" class=\"" + calssName + "\">" + title + "</a></li>";
                    if (parent.Url.IndexOf("#") > -1)
                    {
                        html = "<li><span  class=\"" + calssName + "\">" + title + "</span></li>";
                    }

                    parents.Add(html);

                    parent = parent.ParentNode;
                }

                parents.Reverse();
                parents.Add(String.Format("<li><span class=\"site\">{0}</span></li>", currNode.Title));

                parents.ForEach(node => sb.Append(node));
            }

            sb.Append(" </ul>");
            return(new MvcHtmlString(sb.ToString()));
        }
Beispiel #3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                CurrentDb.SysPageAccessRecord.Add(new SysPageAccessRecord()
                {
                    UserId = User.Identity.GetUserId <int>(), AccessTime = DateTime.Now, PageUrl = filterContext.HttpContext.Request.Url.AbsolutePath, Ip = CommonUtils.GetIP()
                });
                CurrentDb.SaveChanges();
            }

            ILog log = LogManager.GetLogger(CommonSetting.LoggerAccessWeb);

            log.Info(FormatUtils.AccessWeb(User.Identity.GetUserId <int>(), User.Identity.GetUserName()));


            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true) || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true);

            if (!skipAuthorization)
            {
                if (filterContext.HttpContext.Request.Url.AbsolutePath.IndexOf(ManagerUtils.GetLoginPage()) == -1)
                {
                    if (Request.IsAuthenticated)
                    {
                        var userId = User.Identity.GetUserId <int>();
                        var user   = CurrentDb.SysStaffUser.Where(m => m.Id == userId).FirstOrDefault();
                        if (user == null)
                        {
                            Response.Redirect(ManagerUtils.GetLoginPage() + "?out=0");
                        }
                    }
                }
            }
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);


            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true) || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true);

            if (skipAuthorization)
            {
                return;
            }



            #region 判断是否有该权限
            if (permissions != null)
            {
                MessageBoxModel messageBox = new MessageBoxModel();
                messageBox.No    = Guid.NewGuid().ToString();
                messageBox.Type  = MessageBoxTip.Exception;
                messageBox.Title = "You do not have permission to access the possible link timeout ";

                if (!filterContext.HttpContext.Request.IsAuthenticated)
                {
                    messageBox.Content = "Please re <a href=\"javascript:void(0)\" onclick=\"window.top.location.href='" + ManagerUtils.GetLoginPage() + "'\">sigin</a>";
                }

                bool IsHasPermission = HttpContext.Current.User.Identity.IsInPermission(permissions);

                if (!IsHasPermission)
                {
                    bool isAjaxRequest = filterContext.RequestContext.HttpContext.Request.IsAjaxRequest();
                    if (isAjaxRequest)
                    {
                        CustomJsonResult jsonResult = new CustomJsonResult(ResultType.Exception, messageBox.No, messageBox.Title, messageBox);
                        jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                        filterContext.Result           = jsonResult;
                        filterContext.Result.ExecuteResult(filterContext);
                        filterContext.HttpContext.Response.End();
                        return;
                    }
                    else
                    {
                        string masterName = "_LayoutHome";
                        if (filterContext.HttpContext.Request.QueryString["dialogtitle"] != null)
                        {
                            masterName = "_Layout";
                        }

                        filterContext.Result = new ViewResult {
                            ViewName = "MessageBox", MasterName = masterName, ViewData = new ViewDataDictionary {
                                Model = messageBox
                            }
                        };
                        return;
                    }
                }
            }
            #endregion
        }
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);

            filterContext.Result = new RedirectResult(ManagerUtils.GetLoginPage());
        }