public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                filterContext.HttpContext.Response.Redirect("/Home/ErrorPage?error=权限不足,请联系部门管理员配置访问权限");
            }
            List <ActionPower> listPower = new List <ActionPower>();
            string             userNo    = filterContext.HttpContext.User.Identity.Name;

            if (!string.IsNullOrEmpty(userNo))
            {
                byte issupper = 0;
                if (System.Configuration.ConfigurationManager.AppSettings["SupperUsers"].Contains(userNo))
                {
                    issupper = 1;
                }
                //listPower = new PowerManage().GetBusPower(userNo, issupper, IwSystem);
                listPower = new PowerManage().GetBusPower(userNo, issupper, filterContext, IwSystem);
            }
            else
            {
                filterContext.HttpContext.Response.Redirect("/Home/ErrorPage?error=请先登录");
                filterContext.HttpContext.Response.End();
                filterContext.Result = new EmptyResult();
            }
            string controllerName = filterContext.RouteData.Values["controller"].ToString();
            string actionName     = filterContext.RouteData.Values["action"].ToString();
            string msg            = "";

            string query = filterContext.HttpContext.Request.Url.Query;

            if (string.IsNullOrEmpty(ActionKey))
            {
                IsViewAction = true;
            }
            bool   bol  = PowerHandle.PowerValidServer(listPower, userNo, controllerName, actionName, query, ActionKey, IsViewAction, out msg);
            string type = msg.Split('|')[1];

            msg = msg.Split('|')[0];
            if (!bol)
            {
                if (type.ToLower() == "function")
                {
                    filterContext.HttpContext.Response.Write("{Status:false,Msg:\"" + msg + "\",IsPower:1}");
                }
                else
                {
                    filterContext.HttpContext.Response.Redirect("/Home/ErrorPage?error=" + msg);
                }

                filterContext.HttpContext.Response.End();
                filterContext.Result = new EmptyResult();
            }
            base.OnActionExecuting(filterContext);
        }
Пример #2
0
        public JsonResult HasPower(string path)
        {
            bool hasPower = false;

            if (string.IsNullOrEmpty(User.Identity.Name))
            {
                return(Json(new { success = true, result = false }, JsonRequestBehavior.AllowGet));
            }

            string username = User.Identity.Name;

            if (!string.IsNullOrEmpty(path))
            {
                var data = path.Split('/').Where(o => !string.IsNullOrEmpty(o)).ToList();
                if (data.Count == 1)
                {
                    data.Add("Index");
                }

                if (data.Count == 2)
                {
                    string controller = data[0];
                    string action     = data[1];
                    byte   issupper   = 0;
                    if (System.Configuration.ConfigurationManager.AppSettings["SupperUsers"].Contains(username))
                    {
                        issupper = 1;
                    }
                    //listPower = new PowerManage().GetBusPower(userNo, issupper, IwSystem);
                    var    listPower = new PowerManage().GetBusPower(username, issupper, "OperateSys");
                    string message   = string.Empty;
                    hasPower = PowerHandle.PowerValidServer(listPower, username, controller, action, string.Empty, string.Empty, true, out message);
                }
            }

            return(Json(new { success = true, result = hasPower }, JsonRequestBehavior.AllowGet));
        }