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:
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