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。

戻り値

rawURL で示されるページを表す SiteMapNode。対応する SiteMapNode が見つからなかった場合、またはセキュリティ トリミングが有効で、現在のユーザーの SiteMapNode を返すことができない場合は、null

次のコード例では、抽象SiteMapProviderクラスを実装するFindSiteMapNodeクラスに メソッドを実装する方法を示します。 では SimpleTextSiteMapProvider 、 という名前 FindUrlのヘルパー メソッドを使用して、 オブジェクトから現在表示されているページの URL を HttpContext 取得します。

このコード例は、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 正しく解析および処理されていることを確認します。

クラスは XmlSiteMapProvider 、ASP.NET の既定のサイト マップ プロバイダーであり、クラスが保持するさまざまなコレクションのキーとしてオブジェクトの 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

要求されているページの URL とノード情報を比較するために使用する HttpContext

戻り値

現在要求されているページを表す SiteMapNode。対応する SiteMapNodeSiteMapNode にない場合、またはページ コンテキストが null の場合は、null

注釈

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

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

こちらもご覧ください

適用対象