Пример #1
0
        public bool ValidatePermission(AccountModel account, string controller, string action, string filePath)
        {
            bool   bResult    = false;
            string actionName = string.IsNullOrEmpty(ActionName) ? action : ActionName;

            if (account != null)
            {
                List <permModel> perm = null;
                //测试当前controller是否已赋权限值,如果没有从
                //如果存在区域,Seesion保存(区域+控制器)
                if (!string.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }
                perm = (List <permModel>)HttpContext.Current.Session[filePath];
                if (perm == null)
                {
                    using (SysUserBLL userBLL = new SysUserBLL()
                    {
                        sysRightRepository = new SysRightRepository()
                    })
                    {
                        perm = userBLL.GetPermisson(account.Id, controller); //获取当前用户的权限列表
                        HttpContext.Current.Session[filePath] = perm;        //获取的劝降放入会话由Controller调用
                    }
                }
                //home yunxu
                if (controller.ToLower() == "home")
                {
                    return(true);
                }
                //当用户访问index时,只要权限>0就可以访问
                if (actionName.ToLower() == "index")
                {
                    if (perm.Count > 0)
                    {
                        return(true);
                    }
                }
                //查询当前Action 是否有操作权限,大于0表示有,否则没有
                int count = perm.Where(a => a.KeyCode.ToLower() == actionName.ToLower()).Count();
                if (count > 0)
                {
                    bResult = true;
                }
            }
            return(bResult);
        }