示例#1
0
        // establishes the composite menu hierarchy which is present on all pages.

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // build the composite menu tree
                // this tree implements the Composite Design Pattern

                var root = new MenuCompositeItem("root", null);
                var home = new MenuCompositeItem("home", UrlMaker.ToDefault());
                var shop = new MenuCompositeItem("shopping", UrlMaker.ToShopping());
                var prod = new MenuCompositeItem("products", UrlMaker.ToProducts());
                var srch = new MenuCompositeItem("search", UrlMaker.ToSearch());
                var admn = new MenuCompositeItem("administration", UrlMaker.ToAdmin());
                var cust = new MenuCompositeItem("members", UrlMaker.ToMembers());
                var ordr = new MenuCompositeItem("orders", UrlMaker.ToOrders());

                MenuCompositeItem auth;
                if (Request.IsAuthenticated)
                {
                    auth = new MenuCompositeItem("logout", UrlMaker.ToLogout());
                }
                else
                {
                    auth = new MenuCompositeItem("login", UrlMaker.ToLogin());
                }

                shop.Children.Add(prod);
                shop.Children.Add(srch);
                admn.Children.Add(cust);
                admn.Children.Add(ordr);
                root.Children.Add(home);
                root.Children.Add(shop);
                root.Children.Add(admn);
                root.Children.Add(auth);


                TheMenuComposite.MenuItems = root;
            }
        }