SiteMapPath: change the title and link of the last link in chain
-
14-10-2019 - |
Question
Hi Can you advise please any solution? I have a SiteMapPath control and instead of default functionality like
Home > Accounts > User Account
where "User Account" refers to ~/UserAccount.aspx
I would like to overwrite the last node to show info about a current user, i.e.:
Home > Accounts > John White
and "John White" refers to ~/UserAccount.aspx?id=111 ?
Solution
Yeah, you have to inherit from the XmlSiteMapProvider
and override its BuildSiteMap
method. In here you can manipulate any nodes you want at runtime, which will then show up in your SiteMapPath
control.
public class MySiteMapProvider : XmlSiteMapProvider
{
...
public override SiteMapNode BuildSiteMap()
{
var node = base.BuildSiteMap();
var userAccountsNode = this.FindUserAccountsNode(node);
userAccountsNode.ReadOnly = false;
userAccountsNode.Title = ...;
userAccountsNode.Url = ...;
userAccountsNode.ReadOnly = true;
return node;
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow