Welcome to Bilal Haidar [MVP, MCT] Official Blog Sign in | Join | Help

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

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

Published Saturday, August 25, 2007 9:00 AM by BilalHaidar [MVP]

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required)