当前位置: 首页>>代码示例>>C#>>正文


C# ISiteMap.FindSiteMapNode方法代码示例

本文整理汇总了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;
        }
开发者ID:pickist,项目名称:MvcSiteMapProvider,代码行数:36,代码来源:MenuHelper.cs

示例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;
        }
开发者ID:nZeus,项目名称:MvcSiteMapProvider,代码行数:45,代码来源:MenuHelper.cs

示例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);
 }
开发者ID:Guymestef,项目名称:MvcSiteMapProvider,代码行数:10,代码来源:ControllerExtensions.cs


注:本文中的ISiteMap.FindSiteMapNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。