语言

SiteMapProvider.FindSiteMapNode 方法

定义

在派生类中重写时,检索 SiteMapNode 表示页面的对象。

重载

名称 说明
FindSiteMapNode(String)

在派生类中重写时,检索一个 SiteMapNode 对象,该对象表示指定 URL 处的页面。

FindSiteMapNode(HttpContext)

检索一个 SiteMapNode 对象,该对象表示当前请求的页面使用指定的 HttpContext 对象。

FindSiteMapNode(String)

在派生类中重写时,检索一个 SiteMapNode 对象,该对象表示指定 URL 处的页面。

public:
 abstract System::Web::SiteMapNode ^ FindSiteMapNode(System::String ^ rawUrl);
public abstract System.Web.SiteMapNode FindSiteMapNode(string rawUrl);
abstract member FindSiteMapNode : string -> System.Web.SiteMapNode
Public MustOverride Function FindSiteMapNode (rawUrl As String) As SiteMapNode

参数

rawUrl
String

一个 URL,用于标识要为其检索的 SiteMapNode页。

返回

一个 SiteMapNode 表示通过 rawURL标识的页面;否则, null如果未找到相应的内容 SiteMapNode ,或者是否启用了安全修整,并且 SiteMapNode 当前用户无法返回该页。

示例

下面的代码示例演示如何在实现抽象FindSiteMapNode类的类中实现SiteMapProvider方法。 它 SimpleTextSiteMapProvider 使用名为“帮助 FindUrl程序”方法从 HttpContext 对象中获取当前显示页面的 URL。

该代码示例是 SiteMapProvider 类中的一个较大示例的一部分。

// 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;
  }
}
' Implement the FindSiteMapNode method.
Public Overrides Function FindSiteMapNode(ByVal rawUrl As String) As SiteMapNode
  ' Does the root node match the URL?
  If RootNode.Url = rawUrl Then
    Return RootNode
  Else
    Dim candidate As SiteMapNode = Nothing
    ' Retrieve the SiteMapNode that matches the URL.
    SyncLock Me
      candidate = GetNode(siteMapNodes, rawUrl)
    End SyncLock
    Return candidate
  End If
End Function 'FindSiteMapNode
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);
  }
}
Private Function GetNode(ByVal list As ArrayList, ByVal url As String) As SiteMapNode
  Dim i As Integer
  For i = 0 To list.Count - 1
    Dim item As DictionaryEntry = CType(list(i), DictionaryEntry)
    If CStr(item.Key) = url Then
      Return CType(item.Value, SiteMapNode)
    End If
  Next i
  Return Nothing
End Function 'GetNode


' Get the URL of the currently displayed page.
Private Function FindCurrentUrl() As String
  Try
    ' The current HttpContext.
    Dim currentContext As HttpContext = HttpContext.Current
    If Not (currentContext Is Nothing) Then
      Return currentContext.Request.RawUrl
    Else
      Throw New Exception("HttpContext.Current is Invalid")
    End If
  Catch e As Exception
    Throw New NotSupportedException("This provider requires a valid context.", e)
  End Try
End Function 'FindCurrentUrl

注解

派生自类的 SiteMapProvider 类必须实现抽象 FindSiteMapNode 方法。

提供的 URL 可以是虚拟 URL 或绝对 URL。 它也可能是使用应用程序相对语法的 URL,例如 ~/apprelativedirectory。 确保方法的任何实现 FindSiteMapNode 都正确分析和处理应用程序相对语法。

XmlSiteMapProvider 类(ASP.NET 的默认站点地图提供程序)使用 SiteMapNode 对象的 URL 作为类所维护的各种集合中的键。 因此,如果 SiteMapNode 提供 URL,则必须在网站地图提供程序的范围内唯一。 如果未提供 URL,则会生成唯一标识符来标识 。SiteMapNode

实施者说明

在 FindSiteMapNode(String) 重写派生类中的方法时,如果 SiteMapNode 提供程序在当前网站地图中找不到与 URL 匹配的对象,并且提供程序支持子提供程序,请确保将搜索扩展到任何子提供程序。

另请参阅

适用于

FindSiteMapNode(HttpContext)

检索一个 SiteMapNode 对象,该对象表示当前请求的页面使用指定的 HttpContext 对象。

public:
 virtual System::Web::SiteMapNode ^ FindSiteMapNode(System::Web::HttpContext ^ context);
public virtual System.Web.SiteMapNode FindSiteMapNode(System.Web.HttpContext context);
abstract member FindSiteMapNode : System.Web.HttpContext -> System.Web.SiteMapNode
override this.FindSiteMapNode : System.Web.HttpContext -> System.Web.SiteMapNode
Public Overridable Function FindSiteMapNode (context As HttpContext) As SiteMapNode

参数

context
HttpContext

HttpContext用于将节点信息与请求页的 URL 匹配。

返回

一SiteMapNode个表示当前请求的页面;否则,null如果在页面上下文SiteMapNode中SiteMapNode找不到相应的null页面,则为 。

注解

该方法 FindSiteMapNode 调用抽象 FindSiteMapNode 方法,以基于请求的原始 URL 或虚拟路径检索 SiteMapNode 当前请求的页面的对象。 如果未在 /a0> 中找到相应的值,则返回。

默认情况下,该方法 FindSiteMapNode 不会检查用户是否 SiteMapNode 可访问。

另请参阅

适用于