I am getting trouble that SiteMapResolve fires on some pages and doesn't on other.
This is my code.
protected void Page_Load(object sender, EventArgs e)
{
SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ChangeMapPath);
}
private SiteMapNode ChangeMapPath(Object sender, SiteMapResolveEventArgs e)
{
if (SiteMap.CurrentNode != null)
{
// Clone the current node and all of its relevant parents.
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
SiteMapNode tempNode = currentNode;
if (clientId != 0 && tempNode.Title.Equals("Client Notes"))
{
tempNode.Url = tempNode.Url + EncryptQueryString("ParentId=" + clientId.ToString());
}
if (clientId != 0 && tempNode.ParentNode != null && (tempNode.ParentNode.Title.Equals("Client Contacts")))
{
tempNode.ParentNode.Url = tempNode.ParentNode.Url + EncryptQueryString("ParentId=" + clientId.ToString());
}
else if (tempNode.ParentNode != null)
tempNode.ParentNode.Url = tempNode.ParentNode.Url;
return currentNode;
}
return null;
}
Thanks.
Try replace your code
SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ChangeMapPath);
to
foreach (SiteMapProvider mapProvider in SiteMap.Providers)
{
mapProvider.SiteMapResolve += ChangeMapPath;
}
I know this is an old question, but just in case anyone else is still dealing with this issue, the following solution works for me.
It appears that there is an issue with SiteMapResolveEventHandler not ever being removed, so the first event handler that is added, will be the one that gets called after that point.
https://blogs.msdn.microsoft.com/asiatech/2012/11/29/asp-net-case-study-sitemapresolveeventhandler-memory-leakage/
So, you can do exactly as the original poster has done, but you also need to add the following to each page that adds the SiteMapResolveEventHandler.
protected void Page_UnLoad(object sender, EventArgs e)
{
SiteMap.Provider.SiteMapResolve -= new SiteMapResolveEventHandler(this.ChangeMapPath);
}
It should call the appropriate handler on each page if you have forced the removal on previous pages.
Alternatively, instead of using the Page_Unload, you could place the
SiteMap.Provider.SiteMapResolve -= new SiteMapResolveEventHandler(this.ChangeMapPath);
line of code at the beginning of the ChangeMapPath method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With