SiteMapProvider.FindSiteMapNode Método

Definição

Quando substituído em uma classe derivada, recupera um objeto SiteMapNode que representa uma página.When overridden in a derived class, retrieves a SiteMapNode object that represents a page.

Sobrecargas

FindSiteMapNode(String)

Quando substituída em uma classe derivada, recupera um objeto SiteMapNode que representa a página na URL especificada.When overridden in a derived class, retrieves a SiteMapNode object that represents the page at the specified URL.

FindSiteMapNode(HttpContext)

Recupera um objeto SiteMapNode que representa a página solicitada no momento usando o objeto HttpContext especificado.Retrieves a SiteMapNode object that represents the currently requested page using the specified HttpContext object.

FindSiteMapNode(String)

Quando substituída em uma classe derivada, recupera um objeto SiteMapNode que representa a página na URL especificada.When overridden in a derived class, retrieves a SiteMapNode object that represents the page at the specified 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

Parâmetros

rawUrl
String

Uma URL que identifica a página para a qual um SiteMapNodeserá recuperado.A URL that identifies the page for which to retrieve a SiteMapNode.

Retornos

SiteMapNode

Um SiteMapNode que representa a página identificada por rawURL; caso contrário, null se nenhum SiteMapNode correspondente for encontrado ou se a restrição de segurança estiver habilitada e o SiteMapNode não puder ser retornado para o usuário atual.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.

Exemplos

O exemplo de código a seguir demonstra como implementar o FindSiteMapNode método em uma classe que implementa a SiteMapProvider classe abstrata.The following code example demonstrates how to implement the FindSiteMapNode method in a class that implements the abstract SiteMapProvider class. O SimpleTextSiteMapProvider usa um método auxiliar, chamado FindUrl , para obter a URL da página atualmente exibida do HttpContext objeto.The SimpleTextSiteMapProvider uses a helper method, named FindUrl, to get the URL of the currently displayed page from the HttpContext object.

Este exemplo de código faz parte de um exemplo maior fornecido para a SiteMapProvider classe.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;
  }
}
' 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

Comentários

As classes que derivam da SiteMapProvider classe devem implementar o FindSiteMapNode método abstract.Classes that derive from the SiteMapProvider class must implement the abstract FindSiteMapNode method.

A URL fornecida pode ser uma URL virtual ou absoluta.The URL provided can be a virtual or absolute URL. Também pode ser uma URL que usa a sintaxe relativa ao aplicativo, como ~/apprelativedirectory .It might also be a URL that uses application-relative syntax, such as ~/apprelativedirectory. Certifique-se de que qualquer implementação do FindSiteMapNode método analise e manipule a sintaxe relativa ao aplicativo corretamente.Ensure that any implementation of the FindSiteMapNode method parse and handle application-relative syntax properly.

A XmlSiteMapProvider classe, que é o provedor de mapa do site padrão para ASP.net, usa a URL de um SiteMapNode objeto como uma chave nas várias coleções que as classes mantêm.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. Portanto, se um SiteMapNode fornecer uma URL, ele deverá ser exclusivo dentro do escopo do provedor de mapa do site.Therefore, if a SiteMapNode provides a URL, it must be unique within the scope of the site map provider. Se nenhuma URL for fornecida, um identificador exclusivo será gerado para identificar o SiteMapNode .If no URL is provided, a unique identifier is generated to identify the SiteMapNode.

Notas aos Implementadores

Ao substituir o FindSiteMapNode(String) método em uma classe derivada, certifique-se de estender a pesquisa para todos os provedores filho, se um SiteMapNode objeto que corresponda à URL não for encontrado pelo provedor no mapa do site atual e o provedor oferecer suporte a provedores filho.When overriding the FindSiteMapNode(String) 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.

Confira também

Aplica-se a

FindSiteMapNode(HttpContext)

Recupera um objeto SiteMapNode que representa a página solicitada no momento usando o objeto HttpContext especificado.Retrieves a SiteMapNode object that represents the currently requested page using the specified HttpContext object.

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

Parâmetros

context
HttpContext

O HttpContext usado para corresponder as informações de nó com a URL da página solicitada.The HttpContext used to match node information with the URL of the requested page.

Retornos

SiteMapNode

Um SiteMapNode que representa a página solicitada no momento; caso contrário, null, se nenhum SiteMapNode correspondente puder ser localizado no SiteMapNode ou se o contexto da página for null.A SiteMapNode that represents the currently requested page; otherwise, null, if no corresponding SiteMapNode can be found in the SiteMapNode or if the page context is null.

Comentários

O FindSiteMapNode método chama o FindSiteMapNode método abstract para recuperar um SiteMapNode objeto para a página solicitada no momento com base na URL bruta ou no caminho virtual da solicitação.The FindSiteMapNode method calls the abstract FindSiteMapNode method to retrieve a SiteMapNode object for the currently requested page based on the raw URL or the virtual path of the request. Se nenhum correspondente SiteMapNode for encontrado no SiteMap , null será retornado.If no corresponding SiteMapNode is found in the SiteMap, null is returned.

O FindSiteMapNode método não verifica se um SiteMapNode é acessível a um usuário, por padrão.The FindSiteMapNode method does not check whether a SiteMapNode is accessible to a user, by default.

Confira também

Aplica-se a