Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string cacheKey = "AdminBreadCrumb";
            string breadCrumbFileContent = (string)Cache[cacheKey];

            if (string.IsNullOrEmpty(breadCrumbFileContent))
            {
                // cache breadcrumb xml
                string breadCrumbFile = Server.MapPath("~/App_Data/adminbreadcrumb.xml");
                breadCrumbFileContent = File.ReadAllText(breadCrumbFile);
                Cache.Add(cacheKey, breadCrumbFileContent, new CacheDependency(breadCrumbFile), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            }
            XmlDocument breadCrumbMap = new XmlDocument();

            breadCrumbMap.LoadXml(breadCrumbFileContent);
            string pagePath = Request.AppRelativeCurrentExecutionFilePath.ToLowerInvariant();

            if (pagePath.EndsWith("admin/menu.aspx") && !string.IsNullOrEmpty(Request.QueryString["path"]))
            {
                pagePath += "?path=" + Request.QueryString["path"].ToLowerInvariant();
            }
            List <BreadCrumbItem> breadCrumbList = GenerateBreadCrumbList(breadCrumbMap.DocumentElement, pagePath);

            if (breadCrumbList != null)
            {
                foreach (BreadCrumbItem item in breadCrumbList)
                {
                    ProcessRules(item);
                }
                List <BreadCrumbItem> expandedList = new List <BreadCrumbItem>();
                foreach (BreadCrumbItem item in breadCrumbList)
                {
                    expandedList.Add(item);
                    IList <BreadCrumbItem> childItems = GetChildItems(item);
                    if (childItems.Count > 0)
                    {
                        expandedList.AddRange(childItems);
                    }
                }
                // the last link does not need to do anything
                expandedList[expandedList.Count - 1].Url      = "#";
                expandedList[expandedList.Count - 1].CssClass = "current";
                BreadCrumbs.DataSource = expandedList;
                BreadCrumbs.DataBind();
            }
            else
            {
                // no breadcrumb data, hide this control
                this.Controls.Clear();
            }
        }