コード例 #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            #region 认证
            bool isAnoy = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) ||
                          filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true);

            var ClientHook            = new ClientHook <Website.Controllers.ManageClientDataModel>();
            var ManageClientDataModel = ClientHook.GetModel();
            if (!isAnoy && ManageClientDataModel != null)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    var result = new AjaxResult()
                    {
                        IsSuccess = false,
                        Message   = "请重新登录",
                    };

                    filterContext.Result = new JsonResult
                    {
                        Data = result,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        ContentType         = "text/html"
                    };
                }
                else
                {
                    new ActionResult()
                    {
                    }
                }
            }
            #endregion

            #region 授权
            string Controller = filterContext.Controller.ControllerContext.Controller.ToString();
            string ActionName = filterContext.ActionDescriptor.ActionName;
            filterContext.Controller.ViewBag.ActionName     = Controller;
            filterContext.Controller.ViewBag.ControllerName = ActionName;
            #endregion

            #region 初始化配置

            #endregion
        }
コード例 #2
0
        public BaseController()
        {
            this.Entity = DBContextFactory.GetDBContext();
            //取得当前管理员
            var ManageClientDataModel = ClientHook.GetModel();

            if (ManageClientDataModel != null)
            {
                int ManageID = int.Parse(ManageClientDataModel.ID);
                this.CurrentManage = this.Entity.M_Manage.Where(o => o.ID == ManageID).FirstOrDefault();
            }

            //授权
            if (this.CurrentManage != null)
            {
                if (!CurrentManage.RoleIDs.IsNullOrEmpty())
                {
                    var   RoleIDsStr = CurrentManage.RoleIDs.Split(',');
                    int[] RoleIDs    = Array.ConvertAll <string, int>(RoleIDsStr, delegate(string s) { return(int.Parse(s)); });
                    if (RoleIDs.Length > 0)
                    {
                        var M_RoleList = Entity.M_Role.Where(o => RoleIDs.Contains(o.ID)).ToList();
                        if (M_RoleList.Count > 0)
                        {
                            var   MenuIDsList    = M_RoleList.Select(o => o.MenuIDs).ToList();
                            var   MenuIDsListStr = string.Join(",", MenuIDsList);
                            var   MenuIDsStr     = MenuIDsListStr.Split(',');
                            int[] MenuIDs        = Array.ConvertAll <string, int>(MenuIDsStr, delegate(string s) { return(int.Parse(s)); });
                            MenuTree = Entity.M_Menu.Where(o => MenuIDs.Contains(o.ID)).ToList();
                        }
                    }
                }
            }
            MenuTree = Entity.M_Menu.ToList();

            this.ViewBag.Entity   = Entity;
            this.ViewBag.MenuTree = MenuTree;
        }