示例#1
0
        public bool ValiddatePermission(AccountModel account, string controller, string action, string actionPath, string filePath)
        {
            bool   bResult    = false;
            string actionName = ValidateHelper.IsNullOrEmpty(ActionName) ? action : ActionName;

            if (account != null)
            {
                IList <permModel> perm = null;
                //测试当前controller是否已赋权限值,如果没有从
                //如果存在区域,Seesion保存(区域+控制器)
                if (!ValidateHelper.IsNullOrEmpty(Area))
                {
                    controller = Area + "/" + controller;
                }
                perm = (List <permModel>)HttpContext.Current.Session[account.UserCode + ":" + filePath];
                if (perm == null)
                {
                    SysRightApp _appRole = new SysRightApp();
                    perm = _appRole.GetPermission(account.UserCode, filePath);             //获取当前用户的权限列表
                    HttpContext.Current.Session[account.UserCode + ":" + filePath] = perm; //获取的劝降放入会话由Controller调用
                }
                //当用户访问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;
                }
                else
                {
                    bResult = false;
                }
            }
            return(bResult);
        }
        public JsonResult GetPermission()
        {
            //string url = Request.Url.AbsolutePath;
            //url = Request.Path;
            //url = Request.RawUrl;
            //url = Request.Url.PathAndQuery;
            //object con = RouteData.Route.GetRouteData(this.HttpContext).Values["controller"];
            //con = RouteData.Route.GetRouteData(this.HttpContext).Values["action"];
            string url = Request.UrlReferrer.AbsolutePath;

            IList <permModel> list = _rightApp.GetPermission(UserId, url);
            var json = from r in list
                       select new permModel()
            {
                KEYCODE = r.KEYCODE,
                ISVALID = r.ISVALID
            };

            return(Json(json, JsonRequestBehavior.AllowGet));
        }