Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SiteMapProvider.FindSiteMapNode Method (String)

When overridden in a derived class, retrieves a SiteMapNode object that represents the page at the specified URL.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public abstract SiteMapNode FindSiteMapNode(
	string rawUrl
)

Parameters

rawUrl
Type: System.String

A URL that identifies the page for which to retrieve a SiteMapNode.

Return Value

Type: System.Web.SiteMapNode
A SiteMapNode that represents the page identified by rawURL; otherwise, null, if no corresponding SiteMapNode is found or if security trimming is enabled and the SiteMapNode cannot be returned for the current user.

Classes that derive from the SiteMapProvider class must implement the abstract FindSiteMapNode method.

The URL provided can be a virtual or absolute URL. It might also be a URL that uses application-relative syntax, such as ~/apprelativedirectory. Ensure that any implementation of the FindSiteMapNode method parse and handle application-relative syntax properly.

The XmlSiteMapProvider class, which is the default site map provider for ASP.NET, uses the URL of a SiteMapNode object as a key in the various collections that the classes maintain. Therefore, if a SiteMapNode provides a URL, it must be unique within the scope of the site map provider. If no URL is provided, a unique identifier is generated to identify the SiteMapNode.

Notes to Inheritors

When overriding the FindSiteMapNode method in a derived class, be sure to extend the search to any child providers, if a SiteMapNode object that matches the URL is not found by the provider in the current site map and the provider supports child providers.

The following code example demonstrates how to implement the FindSiteMapNode method in a class that implements the abstract SiteMapProvider class. The SimpleTextSiteMapProvider uses a helper method, named FindUrl, to get the URL of the currently displayed page from the HttpContext object.

This code example is part of a larger example provided for the SiteMapProvider class.

// Implement the FindSiteMapNode method. 
public override SiteMapNode FindSiteMapNode(string rawUrl)
{

  // Does the root node match the URL? 
  if (RootNode.Url == rawUrl)
  {
    return RootNode;
  }
  else
  {
    SiteMapNode candidate = null;
    // Retrieve the SiteMapNode that matches the URL. 
    lock (this)
    {
      candidate = GetNode(siteMapNodes, rawUrl);
    }
    return candidate;
  }
}
private SiteMapNode GetNode(ArrayList list, string url)
{
  for (int i = 0; i < list.Count; i++)
  {
    DictionaryEntry item = (DictionaryEntry)list[i];
    if ((string)item.Key == url)
      return item.Value as SiteMapNode;
  }
  return null;
}

// Get the URL of the currently displayed page. 
private string FindCurrentUrl()
{
  try
  {
    // The current HttpContext.
    HttpContext currentContext = HttpContext.Current;
    if (currentContext != null)
    {
      return currentContext.Request.RawUrl;
    }
    else
    {
      throw new Exception("HttpContext.Current is Invalid");
    }
  }
  catch (Exception e)
  {
    throw new NotSupportedException("This provider requires a valid context.",e);
  }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.