Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Sitefinity 4.1 menu fix
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Sitefinity 4.1 menu fix

Feed from this thread
  • Gerrit avatar

    Posted on Apr 29, 2011 (permalink)

    Hi Everyone,

    So I have been experiencing some problems after updating to Sitefinity 4.1, My Menu did not want to apply the security to it anymore.
    I have created my custom menu to fix this problem for the time being. Feel free to use it :)

    Here is the ascx code:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs" Inherits="Medihelp.BrokerToolbox.Controls.MainMenu" %>
    <%@ Register TagPrefix="sitemap" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" Assembly="Telerik.Sitefinity" %>
    <sitemap:SiteMenu EnableOverlay="true" ID="smMainMenu" runat="server" ClickToOpen="false" CollapseAnimation-Type="None" ExpandAnimation-Type="None">
    </sitemap:SiteMenu>

    And here is the CS code :
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
     
    using Telerik.Sitefinity.Web;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Web.UI;
    using Telerik.Web.UI;
    using Telerik.Web.UI.Design;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Configuration;
    using Telerik.Sitefinity.Configuration;
     
    namespace Medihelp.BrokerToolbox.Controls
    {
        [RequireScriptManager]
        public partial class MainMenu : System.Web.UI.UserControl
        {
     
     
     
     
     
     
     
     
     
     
            protected void Page_Load( object sender, EventArgs e )
            {  
                //add event for item databound
                this.smMainMenu.ItemDataBound += new Telerik.Web.UI.RadMenuEventHandler( smMainMenu_OnItemDataBound );
            }
     
     
     
     
     
     
     
     
     
     
            void smMainMenu_OnItemDataBound( object sender, Telerik.Web.UI.RadMenuEventArgs e )
            {
                //get the sitemap node object from the item binded to the control
                SiteMapNode cNode = e.Item.DataItem as SiteMapNode;
     
                //cast so that we can have the node
                PageSiteNode node = ( PageSiteNode )cNode;
     
                //ensure the user may see this node
                if( node.IsAccessibleToUser( HttpContext.Current ) )
                {
                    // Hide the menu item if set to not show in navigation or if hidden
                    if( !node.ShowInNavigation || node.Hidden )
                    {
                        e.Item.Visible = false;
                    }
     
                    // Set group node url to url of first page to fix SF4 Page Group BUG!!!!
                    if( node.IsGroupPage )
                    {
                        //get the first page in the group
                        SiteMapNode gNode = SiteMapBase.GetFirstPageDataNode( node );
     
                        //ensure that the user may access the page
                        if( gNode.IsAccessibleToUser( HttpContext.Current ) )
                        {
                            //set the path
                            e.Item.NavigateUrl = gNode.Url;
                        }
                        else
                        {
                            //user may not see the first item in the group
                            e.Item.NavigateUrl = "javascript:void(0);";
                        }
                    }
     
                    // Set Current Top Level Node to Selected
                    SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
                    if( currentNode != null )
                    {
                        var item = smMainMenu.FindItemByUrl( Page.ResolveUrl( currentNode.Url ) );
                        if( item != null )
                        {
                            SiteMapNode curItem = item.DataItem as SiteMapNode;
                            if( curItem != null )
                            {
                                if( item.Level > 0 )
                                {
                                    // Select top menu item when a sub item is selected
                                    GetRootNode( currentNode );
                                }
                            }
                        }
                    }
                }
                else
                {
                    //the user may not see the page, hide it from the menu
                    e.Item.Visible = false;
                }
            }
     
     
     
     
     
     
     
     
     
     
            /// <summary>
            /// Calls itself until it gets the section one level below the root
            /// </summary>
            /// <param name="node"></param>
            private void GetRootNode( SiteMapNode node )
            {
                if( node.ParentNode.ParentNode == null )
                {
                    var item = smMainMenu.FindItemByValue( node.Title );
                    if( item != null )
                        item.ImageUrl = item.HoveredImageUrl;
                }
                else
                {
                    GetRootNode( node.ParentNode );
                }
            }
     
     
     
     
     
     
     
     
     
     
        }
    }

    The code above is a mix of my code and code I found in the forums.

    The important piece of code is the "IsAccessibleToUser()" which seemed to be missing in the Sitefinity 4.1 menu for some odd reason.

    Kind Regards,
    Gerrit

  • Radoslav Georgiev Radoslav Georgiev admin's avatar

    Posted on May 4, 2011 (permalink)

    Hello Gerrit,

    Thank you for sharing your code. I have updated your Telerik Points. This issue is fixed in Monday's Internal Build .

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Menu > Sitefinity 4.1 menu fix