ASP.NET:自定义动态填充站点地图(SiteMapProvider)

发布于 2024-08-11 08:17:58 字数 351 浏览 2 评论 0原文

我正在尝试编写我自己的第一个 SiteMapProvider 子类。它旨在使用一堆不同的数据库查找动态填充,就像我在网上找到的所有示例一样。

然而,有很多事情我不太清楚。这是我的第一个问题:

  • 为什么几乎每个人的项目中都使用 StaticSiteMapProvider 而不是 SiteMapProvider?由于该类包含名称“static”,所以我的印象是它不像我想要的那样……嗯,动态的。
  • 有人可以为我提供一个超级简约的 SiteMapProvider 子类,它仅使用静态数据填充地图,即没有数据库访问等?

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.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩一世无双 2024-08-18 08:17:58

SiteMapProvider 可以是完全动态的。例如,它可以仅针对节点进行动态查找。与 StaticSiteMapProvider 相比,您应该了解整个结构。所以这由您决定选择什么。

您可以查看XmlSiteMapProvider,这是“静态”地图提供程序的一个很好的示例。

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;
    }
}

我没有检查这个,但应该可以。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文