I have navigation defined in web.sitemap and I want programmaticly disable some siteMapNode. How is it possible?
For example I have next node: And I want disable node if it has roles="Admin"
roleManager is set up like <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" />
and Windows Authorization does not have "Admin" group. It is like Virtual one.
I tried next:
SiteMapNodeCollection tempCollection = new SiteMapNodeCollection(SiteMap.RootNode.ChildNodes);
if (SiteMap.RootNode.ReadOnly)
SiteMap.RootNode.ReadOnly = false;
foreach (SiteMapNode node in tempCollection)
{
if (node.Roles.Contains("Admin"))
{
SiteMap.RootNode.ChildNodes.Remove(node);
}
}
Then I am getting: System.NotSupportedException: Collection is read-only.
Then tried like
SiteMapNodeCollection modifiableCollection = new SiteMapNodeCollection(SiteMap.RootNode.ChildNodes);
foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
{
if (node.Roles.Contains("Admin"))
{
modifiableCollection.Remove(node);
}
}
But after that I dont know how to plug that new collection into navigation (Menu1 object)
Also tried to process every node throw handler, like
SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.SiteMapAccess);
private SiteMapNode SiteMapAccess(Object sender, SiteMapResolveEventArgs e)
{
SiteMapNode RootNode = SiteMap.RootNode.Clone(true);
SiteMapNode tempNode = RootNode;
if (tempNode.Roles.Contains("Admin"))
{
tempNode.RootNode.ChildNodes.Remove(tempNode);
}
return RootNode;
}
But it is throwing that RootNode object should be created before using "new" statement. Although I used next guide: http://msdn.microsoft.com/en-us/library/ms178425.aspx
Any suggestions? http://forums.asp.net/t/894192.aspx here I found interesting discussion where I did not try option with e.Item.Parent.ChildItems.Remove(e.Item)
Here is also interesting example http://stackoverflow.com/questions/12297/how-can-i-remove-nodes-from-a-sitemapnodecollection, but my datasource have SiteMapDataSource type, not Repeater.DataSource