Aug 25 2007

Update on Website Menu + web.sitemap: A smart combination

Category: ASP.NET 2.0 - GeneralBil@l @ 19:00

I have updated the code I presented yesterday in: Website Menu + web.sitemap: A smart combination to handle pages that are not listed in the web.sitemap. Here is the updated code in bold:

        private static string GetSubRootNode()
        {
            // Get the current code
            SiteMapNode current = SiteMap.CurrentNode;
            // Get the root node
            SiteMapNode root = SiteMap.RootNode;
            // Get a copy of the root node
            SiteMapNode node = root;
            string url = "";
   
            // If we are processing the parent node,
            // then return its url.
            if (current != null)
            {
                if (current != root)
                {
                    // We check if the current's parent node
                    // is different from the root, go up
                    // one level in the web.sitemap. Kepp up looping
                    // until the current node's parent is the root
                    while (current.ParentNode != root)
                    {
                        current = current.ParentNode;
                    }
                    node = current;
                }
               
                // If localhost, then remove /CodeSuite/CodeSuiteWeb/
                url = node.Url;
                if (HttpContext.Current.Request.IsLocal)
                    url = url.Substring(24, url.Length - 24);
            }
            return url;
        }

If you still find any problems with the above code, please let me know!

Hope this helps,
Regards

Tags:

Comments are closed