SiteMapResolve

The SiteMap.SiteMapResolve event is set to cause major headaches in ASP.NET 2.0 development. Jeff Prosise talks about the need for the event in a post entitled “Cool ASP.NET 2.0 Programming Trick”. Jeff appears to be taking the wrong approach.

As ASP.NET developers we are accustomed to wiring up events to methods in our Page derived classes. However, SiteMapResolve is a global (defined as public and static) event on the SiteMap class and will fire when resolving a node for any page in the application, not just the subscribing page. Also, we aren’t used to unsubscribing to events in ASP.NET but SiteMapResolve, being a root, will hold on to any references we hand off through a delegate until the universe collapses, or the AppDomain unloads, whichever happens first.

The best solution to work with SiteMapResolve is going to involve a singleton or static class. The best solution I have so far appears to be unfortunately very messy.

Print | posted @ Wednesday, March 16, 2005 5:44 AM

Comments on this entry:

Gravatar # re: SiteMapResolve
by Dan Elleson at 12/3/2005 4:26 PM

No joke.
I have just encountered this very problem and it is a major design flaw. The usefulness of this event would be much, however the usefulness of the event being static is almost none in any case that springs to mind including my current dilema. This is painful.
  
Gravatar # re: SiteMapResolve
by Dan at 3/20/2006 5:48 PM

what if I do
RemoveHandler SiteMap.SiteMapResolve, AddressOf Me.SiteMapModify
inside the handler?
  
Gravatar # re: SiteMapResolve
by scott at 3/21/2006 3:33 AM

Dan: The danger is that two pages could subscribe to the event at the same time. When the event fires, each page will get the event twice, once for itself, and once for the other page. I don't see an easy way to handle that type of race condition.
  
Gravatar # re: SiteMapResolve
by Oskars Podans at 6/15/2006 7:16 AM

i'm desperate about this :(
scott, could you share with your workaround?
though i do not like anything messy.
the best way is to look for another solution not involving SiteMapResolve event.
i'm afraid this leads to writing custom site map provider
  
Gravatar # re: SiteMapResolve
by Sina Ebadi at 9/13/2006 6:22 AM

SiteMapResolve was so shaky for me too, and it had a messy implementation in our application. Do you know any better SiteMap like tool for asp.net?
  
Gravatar # re: SiteMapResolve
by Bernadett Librecz at 2/2/2010 4:21 AM

what about Page_Unload?
protected void Page_Unload(object sender, EventArgs e) {
SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(YOUR FUNCTION);
}
  
Comments have been closed on this topic.
Scott Allen
Posts - 869
Comments - 4493
Stories - 14