Ejemplo n.º 1
0
        /// <summary>
        /// ��ȡ��ǰ�˵�·��
        /// </summary>
        /// <param name="routeData"></param>
        /// <returns></returns>
        public static MenuItem GetCurMenu(RouteData routeData)
        {
            var route = new RouteValueDictionary(routeData.Values);

            if (route.ContainsKey("id"))
            {
                route.Remove("id");
            }

            var url1 = "/" + RouteUtils.Url(routeData.Route, route);
            var id   = GenId(url1);

            MenuItem item;

            MenuTree.TryGetValue(id, out item);
            return(item);
        }
Ejemplo n.º 2
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var ctx = filterContext.Controller.ControllerContext.RequestContext;

            //未登录,采用默认的方式处理
            if (!ctx.HttpContext.User.Identity.IsAuthenticated)
            {
                base.OnAuthorization(filterContext);
                return;
            }
            var routeData = ctx.RouteData;
            var rout      = new RouteValueDictionary();
            var r         = (Route)routeData.Route;
            var list      = new [] { routeData.Values, r.DataTokens, r.Defaults };

            foreach (var s in PartList)
            {
                foreach (var dic in list)
                {
                    var v = dic[s];
                    if (v == null)
                    {
                        continue;
                    }

                    rout[s] = v;
                    break;
                }
            }

            var url1 = RouteUtils.Url(rout);

            Roles = MenuMng.GenId(url1);

            base.OnAuthorization(filterContext);
        }
Ejemplo n.º 3
0
        protected virtual MenuItem CreateMenu()
        {
            //读取当前方法的 action、controller ,
            var menu = new MenuItem
            {
                Title  = Title,
                Icon   = Icon,
                Remark = Remark,
                Sequ   = Sequ,
                Hide   = Hide
            };
            var url = Url;

            if (Info != null)
            {//兼容自动配置的
                menu.ActionName          = Info.Name;
                RouteValue["action"]     = Info.Name;
                RouteValue["controller"] = Info.ReflectedType.Name.Replace("Controller", string.Empty);

                if (!string.IsNullOrEmpty(Modual))
                {
                    RouteValue["modual"] = Modual;
                }

                //读取当前方法的 areas
                {
                    var arr = new List <string>(Info.ReflectedType.FullName.Split('.'));
                    var i   = arr.IndexOf("Areas");
                    if (i >= 0)
                    {
                        RouteValue["area"] = arr[i + 1];
                    }
                }

                url = RouteUtils.Url(RouteValue);
            }

            menu.Url = url;
            menu.Id  = MenuMng.GenId(url);

            if (!string.IsNullOrEmpty(PArea))
            {
                RouteValue["area"] = PArea;
            }
            else if (PArea == string.Empty && RouteValue.ContainsKey("area"))
            {
                RouteValue.Remove("area");
            }

            if (!string.IsNullOrEmpty(PController))
            {
                RouteValue["controller"] = PController;
            }
            else if (PController == string.Empty && RouteValue.ContainsKey("controller"))
            {
                RouteValue.Remove("controller");
            }

            if (!string.IsNullOrEmpty(PAction))
            {
                RouteValue["action"] = PAction;
            }
            else if (PAction == string.Empty && RouteValue.ContainsKey("action"))
            {
                RouteValue.Remove("action");
            }

            if (!string.IsNullOrEmpty(PModual))
            {
                RouteValue["modual"] = PModual;
            }
            else if (PModual == string.Empty && RouteValue.ContainsKey("modual"))
            {
                RouteValue.Remove("modual");
            }

            url = RouteUtils.Url(RouteValue);

            menu.ParentId = MenuMng.GenId(url);

            if (menu.Id == menu.ParentId)
            {
                menu.ParentId = string.Empty;
            }

            return(menu);
        }