SiteMapProvider.FindSiteMapNode メソッド

定義

派生クラスでオーバーライドされると、ページを表す SiteMapNode オブジェクトを取得します。

オーバーロード

名前 説明
FindSiteMapNode(String)

派生クラスでオーバーライドされると、指定した URL にあるページを表す SiteMapNode オブジェクトを取得します。

FindSiteMapNode(HttpContext)

指定したSiteMapNode オブジェクトを使用して、現在要求されているページを表すHttpContext オブジェクトを取得します。

FindSiteMapNode(String)

派生クラスでオーバーライドされると、指定した URL にあるページを表す SiteMapNode オブジェクトを取得します。

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

SiteMapNodeを取得するページを識別する URL。

返品

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 を指定できます。 また、 ~/apprelativedirectoryなどのアプリケーション相対構文を使用する URL である場合もあります。 FindSiteMapNode メソッドの実装で、アプリケーションの相対構文が正しく解析および処理されていることを確認します。

ASP.NET の既定のサイト マップ プロバイダーである XmlSiteMapProvider クラスは、SiteMapNode オブジェクトの URL を、クラスが保持するさまざまなコレクションのキーとして使用します。 そのため、 SiteMapNode が URL を提供する場合は、サイト マップ プロバイダーのスコープ内で一意である必要があります。 URL が指定されていない場合は、 SiteMapNodeを識別するために一意の識別子が生成されます。

注意 (実装者)

派生クラスで FindSiteMapNode(String) メソッドをオーバーライドする場合は、URL に一致する SiteMapNode オブジェクトが現在のサイト マップ内のプロバイダーによって見つからず、プロバイダーが子プロバイダーをサポートしている場合は、必ずすべての子プロバイダーに検索を拡張してください。

こちらもご覧ください

適用対象

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、対応する SiteMapNodeSiteMapNode で見つからない場合、またはページ コンテキストが null場合。

注釈

FindSiteMapNode メソッドは、抽象FindSiteMapNode メソッドを呼び出して、未加工の URL または要求の仮想パスに基づいて、現在要求されているページのSiteMapNode オブジェクトを取得します。 SiteMapNodeに対応するSiteMapが見つからない場合は、nullが返されます。

FindSiteMapNode メソッドは、既定では、SiteMapNodeにユーザーがアクセスできるかどうかを確認しません。

こちらもご覧ください

適用対象