2

I am using the SiteMapPath for my breadcrumb. Currently it displays the path I took to my current page, but I have a message that displays "You are here: Level1 > Level2 > Level3". The SiteMapPath is placed within my MasterPage. I have pages that will not appear on the .sitemap file and thus the breadcrumb will disappear but the message "You are here: " will not. Is there a way for me to check if a URL exist within the .sitemap file? If URL does not exist, I would like to hide the "You are here" message? Thanks.

EDIT I was able to make my code work. Below is the code:

protected void Page_Load(object sender, EventArgs e)
{
    if (SiteMap.Providers["MYSITEMAPPROVIDER"].CurrentNode == null)
    {
        lblMessage.Visible = false;
    }
}
Anna
  • 239
  • 1
  • 7
  • 21

1 Answers1

2

It's easy, have you tried using this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (SiteMap.CurrentNode == null)
        {
            this.lblMessage.Visible = false;
        }
    }

SiteMap contains a static property CurrentNode

I already tested and you can use this approach in a master page, user control or a page

Jupaol
  • 21,107
  • 8
  • 68
  • 100
  • This is not working for me. Is your sitemap using the URLs from a .sitemap file? – Anna Jul 02 '12 at 14:22
  • I printed out the current node's URL and it is outputing a page from the StarterSite of eCommerce Website. Any idea on how I can change the SiteMap to point to my custom .sitemap file? – Anna Jul 02 '12 at 14:48
  • Your code along with this sample code from this thread: http://forums.asp.net/t/1285234.aspx/1 allowed me to figure out how to make my code work. Thanks! =D – Anna Jul 02 '12 at 15:39