tag:blogger.com,1999:blog-8263949408347549596.post3348096103559329493..comments2023-10-23T23:19:01.111+02:00Comments on Object-Oriented Software Development: SiteMapResolve and dynamic site map pathsWiktor Zychlahttp://www.blogger.com/profile/04420514974154487039noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-8263949408347549596.post-45834381690875380722016-12-26T20:07:00.538+01:002016-12-26T20:07:00.538+01:00Thanks for sharing. Worked for meThanks for sharing. Worked for meAnonymoushttps://www.blogger.com/profile/01070403101764128575noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-24967101668773789872013-12-17T20:36:34.405+01:002013-12-17T20:36:34.405+01:00Thanks so much! Bacon saved! Thanks so much! Bacon saved! Anonymoushttps://www.blogger.com/profile/08251747293899931418noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-457785310234113612012-12-13T15:24:51.087+01:002012-12-13T15:24:51.087+01:00Thanks a lot :)Thanks a lot :)Anonymoushttps://www.blogger.com/profile/05510396830638796425noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-6646260517935182742011-12-07T22:31:29.206+01:002011-12-07T22:31:29.206+01:00I was seeing a memory leak in one of my Production...I was seeing a memory leak in one of my Production applications, at first I thought it might be the session transfer I had between Classic ASP and APS.Net. However one of our other developers, utilizing a script to reload an offensive page 1000 times he was able to determine that it was the attachment of the static SiteMapResolveEventHandler on every page load that was causing the memory leak. Thanks to this article I was able to fix the issue and the memory leak is gone.<br /><br />First thing I would like to add is in the first section of the article the Interface section is a little vague. I simply added a class file to my App_Code directory (right click App_Code->Add new Item), select Class and call it Interfaces.cs. Copy the Interface code in the first section of the article into this file, remove everything but the Using statements though so that the Interface is not inside another Class.<br /><br />I also had to had to add a Global.asax page and connecting the code behind is kind of confusing. After adding the .asax file to your solution, right click App_Code and add another class called GlobalApplication to match the above example, be sure to make it inherit : System.Web.HttpApplication, then copy the contents between the tags in the .asax tags into Class in the GlobalApplication.cs file. Erase ever line in the .asax file except for the first line, and add to the first line in the .asax file, Inherits="GlobalApplication".<br /><br />Now if you need to use this in the Master Page follow what Kevin did in the post above me. Keep in mind he changed the name of the the SiteMap, so update the reference in your Application_Start event.<br /><br />You should now be able to add the ISiteMapResolver interface to the Inheritance list of your MasterPage.master.cs file. Be sure to name your SiteMapNode on the Master page the same name as the name of the SiteMapNode in your Interfaces.cs file.Derek Williamshttps://www.blogger.com/profile/01983280335000968309noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-22715218885665835592011-07-25T10:58:41.691+02:002011-07-25T10:58:41.691+02:00I've implemented multiple provider with みう sol...I've implemented multiple provider with みう solution but only default provider is working. What's wrong...?Saifnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-30252954255124090752011-06-21T22:25:03.688+02:002011-06-21T22:25:03.688+02:00You are briliant!You are briliant!Mairusz, Gorzochhttps://www.blogger.com/profile/08646715106096113389noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-69969175531066701292011-06-14T11:16:59.515+02:002011-06-14T11:16:59.515+02:00My SiteMapProvider also is defined in a MasterPage...My SiteMapProvider also is defined in a MasterPage.<br /><br />To overcome the problem I used the following approach in Global.asax.cs:<br /><br /> SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)<br /> {<br /> if (e.Context.CurrentHandler is ISiteMapResolver)<br /> {<br /> return ((ISiteMapResolver)e.Context.CurrentHandler).SiteMapResolve(sender, e);<br /> }<br /> <br /> <br /> var requestedPage = e.Context.CurrentHandler as Page;<br /> if (requestedPage != null)<br /> {<br /> MasterPage currentMasterPage = requestedPage.Master;<br /> while (currentMasterPage != null)<br /> {<br /> if(currentMasterPage is ISiteMapResolver)<br /> {<br /> return ((ISiteMapResolver) currentMasterPage).SiteMapResolve(sender, e);<br /> }<br /><br /> currentMasterPage = currentMasterPage.Master;<br /> }<br /> }<br /><br /> return null;<br /> }<br /><br />BR,<br />KevinKevinhttps://www.blogger.com/profile/18416400849474641570noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-5933794268518399952011-05-26T11:56:55.179+02:002011-05-26T11:56:55.179+02:00Good post. And unfortunately still actual.Good post. And unfortunately still actual.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-70997713457286228192010-09-06T05:07:25.172+02:002010-09-06T05:07:25.172+02:00Can some one explain what the "1" and &q...Can some one explain what the "1" and "2" stands for in creating the SiteMap object?<br /><br />ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-12459148594807977552010-06-17T00:13:28.871+02:002010-06-17T00:13:28.871+02:00Nice clean solution, thanks!Nice clean solution, thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-51205105293798253192010-05-20T07:26:21.395+02:002010-05-20T07:26:21.395+02:00Great post! Thanks Wiktor.
I have an app with dyn...Great post! Thanks Wiktor.<br /><br />I have an app with dynamically added Master Pages containing a SiteMapPath control, and multiple sitemap providers specified in the web.config (<a href="http://msdn.microsoft.com/en-us/library/ms178426(VS.80).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms178426(VS.80).aspx</a>).<br /><br />In order to fire events in the other providers I had to add events to all providers in the global.asax and dynamically set the provider in the masterpage.<br /><br />Don't implement the interface in the master page, just do so on those content pages where you want to do something with the sitemap.<br /><br />void Application_Start(object sender, EventArgs e) <br /> {<br /> // Code that runs on application startup<br /> SiteMapProviderCollection providers = SiteMap.Providers;<br /> foreach (SiteMapProvider provider in providers)<br /> {<br /> SiteMap.Providers[provider.Name].SiteMapResolve += new SiteMapResolveEventHandler(Provider_SiteMapResolve);<br /> }<br /><br /> }<br /> <br />// In masterpage. I chucked this in the Init as I thought best<br />// to do this early in life-cycle. Didn't try elsewhere as it worked.<br />protected void Page_Init(object sender, EventArgs e)<br /> {<br /><br /> SiteMapPath1.SiteMapProvider = "yourNamedProviderInTheWebConfig";<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-78193285847957232342009-10-27T02:21:18.341+01:002009-10-27T02:21:18.341+01:00It was very helpful. thanksIt was very helpful. thanksUnknownhttps://www.blogger.com/profile/00578569948312619657noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-23685937519259906462009-09-30T08:18:21.564+02:002009-09-30T08:18:21.564+02:00Thanks a lot, works great!Thanks a lot, works great!Unknownhttps://www.blogger.com/profile/07472907638211096974noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-20370078338753331132009-07-09T04:30:53.007+02:002009-07-09T04:30:53.007+02:00hi brother
Can i use this solution on the user c...hi brother<br /> Can i use this solution on the user control? My website built on portal.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-29067419086432686012009-07-09T04:30:35.683+02:002009-07-09T04:30:35.683+02:00hi brother
Can i use this solution on the user c...hi brother<br /> Can i use this solution on the user control? My website built on portal.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-62828441977744064902009-03-27T18:52:00.000+01:002009-03-27T18:52:00.000+01:00If you have multiple sitemap providers you'll need...If you have multiple sitemap providers you'll need to use this instead to bind the event:<BR/><BR/>SiteMap.Providers[currentProvider].SiteMapResolve += new SiteMapResolveEventHandler(Provider_SiteMapResolve);<BR/><BR/>Otherwise, seems to be working fine. Thanks!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-71047520558195354002008-11-13T23:52:00.000+01:002008-11-13T23:52:00.000+01:00if you're building the sitemap dynamically via a c...if you're building the sitemap dynamically via a custom sitemap provider, then just set the provider property of your sitemappath to your custom sitemap provider.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-65217306027584773672008-10-21T15:58:00.000+02:002008-10-21T15:58:00.000+02:00You would enter it at the top of the page, outside...You would enter it at the top of the page, outside and above your partial class. With this example's code it would be above the partial class TheSpecificPage:<BR/><BR/>import System.Web.UI.Page;<BR/><BR/>public partial class TheSpecificPage : Page, ISiteMapResolver<BR/>{<BR/> // ...Page code here...<BR/>}JMarchesonihttps://www.blogger.com/profile/08395401726666149597noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-87192374063483337812008-10-20T22:55:00.000+02:002008-10-20T22:55:00.000+02:00an import? how? can you tell me the syntax?an import? how? can you tell me the syntax?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-10702883364383910992008-10-14T23:31:00.000+02:002008-10-14T23:31:00.000+02:00With a master page, try adding an Import for Syste...With a master page, try adding an Import for System.Web.UI.Page. I had to do this to use some features of the Login control and it now works fine. I don't have time to test it with a master page, but if it works please comment back here so I will know for the future!JMarchesonihttps://www.blogger.com/profile/08395401726666149597noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-55568595249532463552008-10-08T23:48:00.000+02:002008-10-08T23:48:00.000+02:00Even when I try to write the handler code in each ...Even when I try to write the handler code in each page or the base page The current node becomes null and an exception occur.Could any one help today?!Nabeel AL Kaffhttps://www.blogger.com/profile/02079136387172721812noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-90962428094958128672008-10-08T22:35:00.000+02:002008-10-08T22:35:00.000+02:00I also have the same MasterPage problem.My website...I also have the same MasterPage problem.My website has two master pages.The first MasterPage send the query string to the second one which has the navigation menu which has the links that should be modified to include the querystring.I hove someone help us soon to solve this problem...Nabeel AL Kaffhttps://www.blogger.com/profile/02079136387172721812noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-69351933399413166502008-10-06T10:15:00.000+02:002008-10-06T10:15:00.000+02:00Hi,this is a very useful hint.however i have a pro...Hi,<BR/>this is a very useful hint.<BR/>however i have a problem implementing this in a master page. the application never call the SiteMapResolve method. if i put this in the defalut.aspx it works properly, but this would mean that i have to add this method to all the pages of the website. do you have any suggestion?<BR/>thanks,Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-39167601518308353672008-10-05T19:53:00.000+02:002008-10-05T19:53:00.000+02:00Hi,i'm a newbie in C# and .NET, so maybe it is a s...Hi,<BR/>i'm a newbie in C# and .NET, so maybe it is a stupid question but <BR/><BR/>I'm trying to use a sitemappath in a masterpage, but i want to be able to change programmatically the text dysplayed upon the querystring value.<BR/>I'd really like to implement your solution. <BR/><BR/>so the question is...<BR/>Where do i have to declare the interface?<BR/><BR/>ThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-1938154194547181512008-05-08T11:11:00.000+02:002008-05-08T11:11:00.000+02:00Hi, this seems to work fine when i have a static s...Hi, this seems to work fine when i have a static site map (from an xml file) but i have just implemented this solution on a site which has a dynamic site map and have some problems.<BR/><BR/>The build in provider model is kinda limited if the number of dynamic pages grows, therefore i implemented the solution found at:<BR/><BR/>http://www.codeproject.com/KB/aspnet/dynamicsitemap.aspx<BR/><BR/>My SiteMapProvider contains the following methods:<BR/><BR/>protected override SiteMapNode GetRootNodeCore()<BR/>{<BR/> this.Clear();<BR/> return this.BuildSiteMap();<BR/>}<BR/><BR/>public override SiteMapNode BuildSiteMap()<BR/>{<BR/> lock (this)<BR/> {<BR/> if (_root != null)<BR/> return _root;<BR/><BR/> _root = new SiteMapNode(this, "/", "/", "Home");<BR/> this.AddNode(_root);<BR/><BR/> return _root;<BR/> }<BR/>}<BR/><BR/>public SiteMapNode Stack(SiteMapNode node)<BR/>{<BR/> return this.Stack(node, _root);<BR/>}<BR/><BR/>public SiteMapNode Stack(SiteMapNode node, SiteMapNode parent)<BR/>{<BR/> lock (this)<BR/> {<BR/> node.ParentNode = parent;<BR/> this.AddNode(node);<BR/> return node;<BR/> }<BR/>}<BR/><BR/>public void Stack(List<SiteMapNode> nodes)<BR/>{<BR/> SiteMapNode parent = this.RootNode;<BR/><BR/> foreach (SiteMapNode node in nodes)<BR/> {<BR/> parent = this.Stack(node, parent);<BR/> }<BR/>}<BR/><BR/>protected override void Clear()<BR/>{<BR/> lock (this)<BR/> {<BR/> _root = null;<BR/> base.Clear();<BR/> }<BR/>}<BR/><BR/>And all my pages inherit from a base page which stacks the nodes and builds the site map (for that page based on the url). However when using the SiteMapResolve event i have found that every once in a while SiteMap.CurrentNode returns null and throws an exception in my code. I can bypass this by building the whole path in the SiteMapResolve but this seems more of a hack.<BR/><BR/>Please note however that the problem existed with the better site map resolve approach described on codeplex. So your approach is still an improvement.Anonymousnoreply@blogger.com