ASP.NET: custom dynamically populated site map (SiteMapProvider)

I am trying to write my first own SiteMapProvidersubclass. It is designed to dynamically populate using many different database queries, like all the examples I found on the Internet.

However, there are a whole bunch of things that I do not quite understand. Here are my first two questions:

  • Why is StaticSiteMapProviderused in almost all projects instead SiteMapProvider? Since the class contains the name "static", I get the impression that it is not ... well, dynamic, as I want it.
  • Can someone provide me with a super-minimalistic subclass SiteMapProviderthat populates the map using only static data, i.e. without access to the database, etc.?
+3
source share
1 answer

SiteMapProvidercan be total dynamic. For example, it can perform a dynamic search for nodes only. Unlike StaticSiteMapProvider, you should know the whole structure. So, it is for you to decide what to choose.

You can see XmlSiteMapProviderthis is a good example of a static map provider.

public class CoolMapProvider : StaticSiteMapProvider
{
    public override SiteMapNode BuildSiteMap()
    {
        var root = new SiteMapNode(this, "test", "~/test.aspx");
        base.AddNode(root, null);

        base.AddNode(new SiteMapNode(this, "test-child", "~/test_child.aspx"), root);

        return root;
    }
}

I have not tested this, but should work.

+3
source

Source: https://habr.com/ru/post/1722606/


All Articles