Reputation: 11755
In my Asp.Net MVC3
application I am using sitemap
.
I have some scenario that i want to edit sitemap file dynamically
during run time.
I just tired removing a node
and adding a new one
instead of that.
I tried with following code
SiteMapNode node = FindSiteMapNodeFromKey("test");
SiteMapNode no = node.ParentNode;
RemoveNode(node);
mRootNode = new SiteMapNode(this, "Deleted Home", "Default.aspx", "Home");
no.ChildNodes.Add(mRootNode);.
But the node became null
. I have a sitemap node with key test in my sitemap
<mvcSiteMapNode title="Delete" action="Delete" key="test" roles="testrole"/>
Any idea forachieving this properly will really helpful for me.
Upvotes: 0
Views: 523
Reputation: 56849
For editing the sitemap dynamically, you can either use a custom implementation of IDynamicNodeProvider or a custom implementation of ISiteMapBuilder.
The former is easier to do, the latter gives you more control over the nodes. Also, in order to use ISiteMapBuilder, you must use an external DI container so you can replace the built-in implementations with your own.
Note depending on how often you are updating the nodes, you may need to tweak the caching settings as well.
Upvotes: 1