共用方式為


Source to the StaticSiteMapProvider and XmlSiteMapProvider (and others) availible for download.

I might be more excited about this than I was about the Web Application Projects preview we just released...

One of the last things I worked on in the ASP.NET runtime test team was validating a version of the sources of our providers so that users could download them and see first hand what our design practices are.  That work is finally availible to you.

I spend a large portion of my blogging efforts and forum responses trying to promote good designs or revealing little snippets of how we implemented the StaticSiteMapProvider and the XmlSiteMapProvider.  Now, the sources for these providers are availible for download all ASP.NET users and users can see examples of well written providers or copy the code to help bootstrap their own projects.

Download here: https://download.microsoft.com/download/a/b/3/ab3c284b-dc9a-473d-b7e3-33bacfcc8e98/ProviderToolkitSamples.msi
More Info here: https://msdn.microsoft.com/asp.net/downloads/providers/default.aspx

One note: Functionally these providers are nearly equivelent to those actually in the framework, but because they occasionally used some internal APIs, we had to alter a few calls to use public methods instead as well as some other minor changes.

Comments

  • Anonymous
    July 16, 2006
    Hello,

    sorry not for a very appropriate place to post my question, by after downloading provider sources i was inspired to write my own provider. Let's say I named it PathProvider and it is assimple as:

    public class PathProvider : StaticSiteMapProvider
    {
       private SiteMapNode node;
       private SiteMapNode rootNode;
       private SiteMapNode parentNode;

       public PathProvider()
       { }

       public override SiteMapNode BuildSiteMap()
       {
           lock (this)
           {
               base.Clear();
               rootNode = node = CreateNode("root", "Home", "default.aspx");
               base.AddNode(node, null);
               parentNode = node;
               node = CreateNode("test1", "Test 1", "test1.aspx");
               base.AddNode(node, parentNode);
               parentNode = node;
               node = CreateNode("test2", "Test 2", "test2.aspx");
               base.AddNode(node, parentNode);
           }
           return rootNode;
       }

       protected override SiteMapNode GetRootNodeCore()
       {
           BuildSiteMap();
           return rootNode;
       }

       protected virtual SiteMapNode CreateNode(string key, string url, string title)
       {
           return new SiteMapNode(this, key, url, title);
       }
    }

    So, as you can see it's very primitive, After this I added the following snippet to the web.config:
    <siteMap defaultProvider="PathProvider">
               <providers>
                   <clear/>
                   <add name="PathProvider" type="PathProvider"/>
               </providers>
           </siteMap>

    And finally I added to one of my pages SiteMapPath control:
    <asp:SiteMapPath ID="pathMenu" SiteMapProvider="PathProvider" runat="server" />

    But after all, SiteMapPath control is not visible (or better to say, is not being rendered). What I'm doing wrong?
  • Anonymous
    August 02, 2006
    The most common reason why the SiteMapPath control would not be visible is that the CurrentNode didn't resolve.  You can debug this two ways.  1) Set a breakpoint in CurrentNode (may need to override it) in your provider and start tracing the calls (stepping in) to see how your provider is responding  2) Add a SiteMapDataSource and a TreeView control to get an overall picture of what the data is being returned from your provider.  You may find that you see nothing in the TreeView in which case you'll need to debug your provider in more detail.
  • Anonymous
    August 03, 2006
    Well, Treeview and Menu controls produce correct items (and they are visible), but that not true for SiteMapPath :(

    Any ideas, Danny?
  • Anonymous
    August 04, 2006
    This is exactly the scenario I was describing above.  The reason that the SiteMapPath does not show is that SiteMap.CurrentNode is returning nothing.  There is probably a coding error in your provider.  You can prove this by calling SiteMap.CurrentNode form Page_Load and looking at the return value.  I suggest that you put a breakpoint in the CurrentNode function in your provider (override it if there isn't and just call into the base) and Trace the calls.  That is the best way to find out what is happening.