Is it possible to use ASP.NET Sitemap to generate Breadcrumbs?

I want my ASP.NET site to have a simple aka Breadcrumbs menu bar. I created a Sitemap with all the necessary elements and registered in Web.config. For example:

<siteMap>
    <siteMapNode url="Default.aspx" title="Home" >
        <siteMapNode url="hosting/Default.aspx" title="Hosting" />
        <siteMapNode url="software/Default.aspx" title="Software">
            <siteMapNode url="firefox/Default.aspx" title="Firefox">
                <siteMapNode url="Download.aspx" title="Download" />
                <siteMapNode url="Support.aspx" title="Support" />
            </siteMapNode>
        </siteMapNode>
    </siteMapNode>
</siteMap>

And he created a control located on the main page. Here is the code generating code:

protected void Control_Load(Object sender, EventArgs e)
{
    string path = String.Empty;
    StringCollection list = new StringCollection();

    foreach (string str in Request.Url.Segments)
    {
        path += str;
        string link = String.Format("<a href=\"{0}://{1}{2}\">{3}</a>", Request.Url.Scheme, Request.Url.Authority, path, this.names[str]);
        list.Add(link);
    }

    foreach (string str in list)
    {
        menu += String.Concat(str, SeparatorLine);
    }
    menu = menu.Remove(menu.LastIndexOf(SeparatorLine));
}

But it uses StringDictionary, for example {{"/", "Home"}, {"Hosting /", "Hosting"}, {"Software /", "Software"} ..}

How can I use a sitemap request instead? Or maybe something else, not a Sitemap, but invented in advance.

+3
source share
3

ASP.NET SiteMapPath Control

<asp:SiteMapPath ID="SiteMapPath1" Runat="server" />
+9
+5

SiteMapProvider , , . SiteMapPath div CSS div .

, . , . , Sitemap SiteMapDataSource , node.

!

+1

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


All Articles