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

穿精又带淫゛_ 提交于 2019-12-01 07:12:11

问题


I'm trying to write my first very own SiteMapProvider subclass. It is meant to be populated dynamically using a bunch of different database lookups, much like all of the examples I've found on the web.

However, there are a whole bunch of things that are quite unclear to me. Here are my two first questions:

  • Why is StaticSiteMapProvider used in virtually everyone's project instead of SiteMapProvider? Since the class contains the name "static", I'm getting the impression that it's not as...well, dynamic as I want it.
  • Can someone provide me with a super-minimalistic SiteMapProvider subclass which populates the map using only static data, i.e. no database access, etc.?

回答1:


SiteMapProvider can be tottaly dynamic. For example it can make dynamic lookup just for nodes. In contrast with StaticSiteMapProvider you should know whole structure. So this for you to decide what to choose.

You can look at the XmlSiteMapProvider, this is good example of "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 did not checked this, but should work.



来源:https://stackoverflow.com/questions/1716573/asp-net-custom-dynamically-populated-site-map-sitemapprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!