SiteMapProvider.FindSiteMapNode 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在派生类中被重写时,将检索表示某个页的 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程序”方法从 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 的默认网站地图提供程序,它使用对象的 URL SiteMapNode 作为类所维护的各种集合中的键。 因此,如果 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
用于使节点信息与被请求页的 URL 匹配的 HttpContext。
返回
表示当前请求页的 SiteMapNode;如果在 SiteMapNode 中未找到对应的 SiteMapNode,或者页上下文为 null,则为 null。
注解
该方法 FindSiteMapNode 调用抽象 FindSiteMapNode 方法,以根据请求的原始 URL 或请求的虚拟路径检索 SiteMapNode 当前请求页面的对象。 If no corresponding SiteMapNode is found in the SiteMap, null is returned.
默认情况下,该方法 FindSiteMapNode 不会检查用户是否 SiteMapNode 可访问。