本文整理汇总了C#中ISiteMap.FindSiteMapNode方法的典型用法代码示例。如果您正苦于以下问题:C# ISiteMap.FindSiteMapNode方法的具体用法?C# ISiteMap.FindSiteMapNode怎么用?C# ISiteMap.FindSiteMapNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISiteMap
的用法示例。
在下文中一共展示了ISiteMap.FindSiteMapNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentNode
/// <summary>
/// This determines the deepest node matching the current HTTP context, so if the current URL describes a location
/// deeper than the site map designates, it will determine the closest parent to the current URL and return that
/// as the current node. This allows menu relevence when navigating deeper than the sitemap structure designates, such
/// as when navigating to MVC actions, which are not shown in the menus
/// </summary>
/// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
/// <returns></returns>
public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap)
{
// get the node matching the current URL location
var currentNode = selectedSiteMap.CurrentNode;
// if there is no node matching the current URL path,
// remove parts until we get a hit
if (currentNode == null)
{
var url = HttpContext.Current.Request.Url.LocalPath;
while (url.Length > 0)
{
// see if we can find a matching node
currentNode = selectedSiteMap.FindSiteMapNode(url);
// if we get a hit, stop
if (currentNode != null) break;
// if not, remove the last path item
var lastSlashlocation = url.LastIndexOf("/");
if (lastSlashlocation < 0) break; // protects us from malformed URLs
url = url.Remove(lastSlashlocation);
}
}
return currentNode;
}
示例2: GetCurrentNode
/// <summary>
/// This determines the deepest node matching the current HTTP context, so if the current URL describes a location
/// deeper than the site map designates, it will determine the closest parent to the current URL and return that
/// as the current node. This allows menu relevance when navigating deeper than the sitemap structure designates, such
/// as when navigating to MVC actions, which are not shown in the menus
/// </summary>
/// <param name="selectedSiteMapProvider">the current MVC Site Map Provider</param>
/// <param name="returnRootNodeIfNotFound">whether to return the root node if the current node is null</param>
/// <returns></returns>
public static ISiteMapNode GetCurrentNode(ISiteMap selectedSiteMap, bool returnRootNodeIfNotFound)
{
// get the node matching the current URL location
var currentNode = selectedSiteMap.CurrentNode;
// if there is no node matching the current URL path,
// remove parts until we get a hit
if (currentNode == null)
{
var url = HttpContext.Current.Request.Url.LocalPath;
var queryString = HttpContext.Current.Request.Url.Query;
while (url.Length > 0)
{
// see if we can find a matching node
currentNode = selectedSiteMap.FindSiteMapNode(url + queryString);
// if we get a hit, stop
if (currentNode != null) break;
// if not, remove the last path item
var lastSlashlocation = url.LastIndexOf("/");
if (lastSlashlocation < 0) break; // protects us from malformed URLs
url = url.Remove(lastSlashlocation);
}
}
// If the current node is still null, return the root node.
// This is the same way the SiteMap.FindSiteMapNode(rawUrl) method worked in v3.
if (currentNode == null && returnRootNodeIfNotFound)
{
currentNode = selectedSiteMap.RootNode;
}
return currentNode;
}
示例3: GetCurrentSiteMapNodeForChildAction
/// <summary>
/// Gets the current site map node for child action.
/// </summary>
/// <param name="controller">The controller.</param>
/// <param name="provider">The provider.</param>
/// <returns></returns>
public static ISiteMapNode GetCurrentSiteMapNodeForChildAction(this ControllerBase controller, ISiteMap siteMap)
{
return siteMap.FindSiteMapNode(controller.ControllerContext);
}