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


C# SiteMapNode类代码示例

本文整理汇总了C#中SiteMapNode的典型用法代码示例。如果您正苦于以下问题:C# SiteMapNode类的具体用法?C# SiteMapNode怎么用?C# SiteMapNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SiteMapNode类属于命名空间,在下文中一共展示了SiteMapNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildForStore

        public static string BuildForStore(MerchantTribeApplication app)
        {
            if (app == null) return string.Empty;

            string root = app.CurrentStore.RootUrl();
            SiteMapNode rootNode = new SiteMapNode();

            // home
            rootNode.AddUrl(root);
            // sitemap
            rootNode.AddUrl(root + "sitemap");

            // Categories
            foreach (Catalog.CategorySnapshot cat in app.CatalogServices.Categories.FindAll())
            {
                string caturl = Utilities.UrlRewriter.BuildUrlForCategory(cat, app.CurrentRequestContext.RoutingContext);
                rootNode.AddUrl(root.TrimEnd('/') + caturl);
            }

            // Products
            foreach (Catalog.Product p in app.CatalogServices.Products.FindAllPaged(1,3000))
            {
                string produrl = Utilities.UrlRewriter.BuildUrlForProduct(p, app.CurrentRequestContext.RoutingContext, string.Empty);
                rootNode.AddUrl(root.TrimEnd('/') + produrl);
            }
            return rootNode.RenderAsXmlSiteMap();
        }
开发者ID:KimRossey,项目名称:MerchantTribe,代码行数:27,代码来源:SiteMapGenerator.cs

示例2: IsAccessibleToUser

        /// <summary>
        /// Determines whether node is accessible to user.
        /// </summary>
        /// <param name="controllerTypeResolver">The controller type resolver.</param>
        /// <param name="provider">The provider.</param>
        /// <param name="context">The context.</param>
        /// <param name="node">The node.</param>
        /// <returns>
        /// 	<c>true</c> if accessible to user; otherwise, <c>false</c>.
        /// </returns>
        public virtual bool IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node)
        {
            // Is security trimming enabled?
            if (!provider.SecurityTrimmingEnabled)
            {
                return true;
            }

            // Use child modules
            bool result = true;
            foreach (var module in ChildModules)
            {
                try
                {
                    result &= module.IsAccessibleToUser(controllerTypeResolver, provider, context, node);
                }
                catch (AclModuleNotSupportedException)
                {
                    result &= true; // Convention throughout the provider: if the IAclModule can not authenticate a user, true is returned.
                }
                if (result == false)
                {
                    return false;
                }
            }

            // Return
            return result;
        }
开发者ID:noamberda,项目名称:MvcSiteMapProvider,代码行数:39,代码来源:DefaultAclModule.cs

示例3: IsVisible

        public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
        {
            bool returnMe = false;
            var mvcNode = node as MvcSiteMapNode;
            Models.User user = context.Session["CurrentUser"] as Models.User;
            string visibilitySettings = mvcNode == null ? "" : mvcNode["requireLoggedIn"];
            string roleSettings = mvcNode == null ? "" : mvcNode["customRoles"];
            string[] allowedRoles = (roleSettings ?? "").Split(',').Select(x => x.Trim()).ToArray();
            List<string> currentRoles = new List<string>();
            if (user != null && user.Roles != null)
                currentRoles = user.Roles.Select(x => x.Name).ToList();

            if (visibilitySettings == "true" && user == null)
            {
                returnMe = false;
            }
            else
            {
                if (allowedRoles.Contains("*"))
                {
                    returnMe = true;
                }
                else if (allowedRoles.Intersect(currentRoles).Any())
                {
                    returnMe = true;
                }
                else
                {
                    returnMe = false;
                }
            }

            return returnMe;
        }
开发者ID:SigmundArcturus,项目名称:ProjectSafehouse,代码行数:34,代码来源:CustomSiteMapNodeVisibility.cs

示例4: CreateBreadcrumpNode

        private static IHtmlElement CreateBreadcrumpNode(SiteMapNode siteMapNode, Predicate<IHtmlElement> isLastCondition)
        {
            var wrapper = new HtmlElement("li")
                .AddCssClass("toolbar-menu-item")
                .ToggleCssClass("toolbar-menu-current", element => ReferenceEquals(siteMapNode, System.Web.SiteMap.CurrentNode));

            var url = String.IsNullOrEmpty(siteMapNode.Url)
                          ? "javascript:void(0);"
                          : VirtualPathUtility.ToAbsolute(siteMapNode.Url);
            var anchor = new HtmlElement("a", TagRenderMode.Normal)
                .Attribute("href", url)
                .Attribute("title", siteMapNode.Description)
                .ToggleCssClass("home", element => ReferenceEquals(siteMapNode, System.Web.SiteMap.RootNode))
                .ToggleCssClass("last", isLastCondition)
                .AppendTo(wrapper);

            if (String.IsNullOrEmpty(siteMapNode.Title))
            {
                anchor.Html("&nbsp;");
            }
            else
            {
                anchor.Text(siteMapNode.Title);
            }

            return wrapper;
        }
开发者ID:VlaTo,项目名称:EmpRe.NET,代码行数:27,代码来源:Breadcrump.cs

示例5: XmlSiteMapResult

 /// <summary>
 /// Initializes a new instance of the <see cref="XmlSiteMapResult"/> class.
 /// </summary>
 /// <param name="rootNode">The root node.</param>
 /// <param name="url">The base URL.</param>
 /// <param name="siteMapUrlTemplate">The site map URL template.</param>
 public XmlSiteMapResult(SiteMapNode rootNode, string url, string siteMapUrlTemplate)
 {
     Ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
     RootNode = rootNode;
     Url = url;
     SiteMapUrlTemplate = siteMapUrlTemplate;
 }
开发者ID:tshwangq,项目名称:MvcSiteMapProvider,代码行数:13,代码来源:XmlSiteMapResult.cs

示例6: BuildForStore

        public static string BuildForStore(MerchantTribeApplication app)
        {
            if (app == null) return string.Empty;

            string root = app.CurrentStore.RootUrl();
            SiteMapNode rootNode = new SiteMapNode();
            
            // home
            rootNode.AddUrl(root);
            // sitemap
            rootNode.AddUrl(root + "sitemap");

            // Categories
            foreach (Catalog.CategorySnapshot cat in app.CatalogServices.Categories.FindAll())
            {                
                string caturl = Utilities.UrlRewriter.BuildUrlForCategory(cat, app.CurrentRequestContext.RoutingContext);
                
                // Skip Pages with Outbound links as they aren't supported in sitemap format
                string temp = caturl.ToUpperInvariant();
                if (temp.StartsWith("HTTP:") || temp.StartsWith("HTTPS:")) continue;

                rootNode.AddUrl(root.TrimEnd('/') + caturl);
            }

            // Products
            foreach (Catalog.Product p in app.CatalogServices.Products.FindAllPaged(1,3000))
            {
                string produrl = Utilities.UrlRewriter.BuildUrlForProduct(p, app.CurrentRequestContext.RoutingContext, string.Empty);
                rootNode.AddUrl(root.TrimEnd('/') + produrl);
            }
            return rootNode.RenderAsXmlSiteMap();                        
        }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:32,代码来源:SiteMapGenerator.cs

示例7: Generate

        private static string Generate(RequestContext requestContext, SiteMapNode navigationItem, RouteValueDictionary routeValues)
        {
            Check.Argument.IsNotNull(requestContext, "requestContext");
            Check.Argument.IsNotNull(navigationItem, "navigationItem");

            var urlHelper = new UrlHelper(requestContext);
            string generatedUrl = null;

            if (!string.IsNullOrEmpty(navigationItem.RouteName))
            {
                generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, routeValues);
            }
            else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName))
            {
                generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, routeValues, null, null);
            }
            else if (!string.IsNullOrEmpty(navigationItem.Url))
            {
                generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) ?
                               urlHelper.Content(navigationItem.Url) :
                               navigationItem.Url;
                //var rgx = new Regex(@"#.*$");
                //if(rgx.IsMatch(generatedUrl))
                //{
                //    generatedUrl = rgx.Match(generatedUrl).Value;
                //}
            }
            else if (routeValues.Any())
            {
                generatedUrl = urlHelper.RouteUrl(routeValues);
            }

            return generatedUrl;
        }
开发者ID:gowhy,项目名称:LoveBank,代码行数:34,代码来源:SiteMapNodeExtensions.cs

示例8: AddChildNodes

    public void AddChildNodes(ref SiteMapNode parentNode, PageCollection links)
    {
        //you can change this as needed
        string rewrittenDirectory = "~/view/";
        foreach (Page link in links)
        {
            if (link.ParentID.HasValue)
            {
                if (link.ParentID.Value.ToString() == parentNode.Key)
                {
                    string url = link.PageUrl;
                    var rolelist = link.Roles.Split(new char[] { ',', ';' }, 512);
                    if (!url.Contains("registered/") & !url.Contains("admin/"))
                    {
                        url = rewrittenDirectory + url;
                    }
                    // Create a SiteMapNode
                    SiteMapNode node = new SiteMapNode(this, link.PageID.ToString(), url, link.MenuTitle, link.Summary, rolelist, null, null, null);
                    AddNode(node, parentNode);
                    AddChildNodes(ref node, links);
                }
            }

        }
    }
开发者ID:hondoslack,项目名称:territorysite,代码行数:25,代码来源:SubSonicSiteMapProvider.cs

示例9: IsVisible

        public bool IsVisible(SiteMapNode node, HttpContext context, IDictionary<string, object> sourceMetadata)
        {
            // Convert to MvcSiteMapNode
            var mvcNode = node as MvcSiteMapNode;
            if (mvcNode == null)
                return true;

            // Is visibility attribute specified?
            string visibility = mvcNode["visibility"];

            if (string.IsNullOrEmpty(visibility))
                return true;

            visibility = visibility.Trim();

            //Process visibility
            switch (visibility)
            {
                case "Auth":

                    return context.Request.IsAuthenticated;

                case "!Auth":

                    return !context.Request.IsAuthenticated;

                default:

                    return context.Request.IsAuthenticated && Roles.GetRolesForUser().Intersect(visibility.Split(',')).Count() > 0;
            }
        }
开发者ID:Supermakaka,项目名称:GitTest,代码行数:31,代码来源:VisibilityProvider.cs

示例10: FindRoutesForNode

        protected virtual RouteData FindRoutesForNode(SiteMapNode node, HttpContextBase httpContext)
        {
            RouteData routeData = null;

            // create a uri for the current node.  If we have an absoluteURL,
            // it will be used instead of the baseUri
            var nodeUri = new Uri(httpContext.Request.Url, node.Url);

            // create textwriter with null stream, we don't want to output anything to it
            using (var nullWriter = new StreamWriter(Stream.Null))
            {
                // create a new http context using the node's URL instead of the current one.
                var nodeRequest = new HttpRequest(string.Empty, nodeUri.ToString(), nodeUri.Query);
                var nodeResponse = new HttpResponse(nullWriter);
                var nodeContext = new HttpContext(nodeRequest, nodeResponse);
                var nodeHttpContext = new HttpContextWrapper(nodeContext);

                var routes = RouteTable.Routes;
                //if(!string.IsNullOrEmpty(node.Route))
                //{
                //    routeData = routes[node.Route].GetRouteData(nodeHttpContext);
                //}
                //else
                //{
                routeData = routes.GetRouteData(nodeHttpContext);
                //}

                return routeData;
            }
        }
开发者ID:ghost1face,项目名称:Mvc5SiteMapBuilder,代码行数:30,代码来源:AuthorizeAttributeAclModule.cs

示例11: BuildModel

        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="startingNode">The starting node.</param>
        /// <returns>The model.</returns>
        private static SiteMapPathHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode)
        {
            // Build model
            var model = new SiteMapPathHelperModel();
            var node = startingNode;
            while (node != null)
            {
                var mvcNode = node as MvcSiteMapNode;

                // Check visibility
                bool nodeVisible = true;
                if (mvcNode != null)
                {
                    nodeVisible = mvcNode.VisibilityProvider.IsVisible(
                        node, HttpContext.Current, SourceMetadata);
                }

                // Check ACL
                if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current))
                {
                    // Add node
                    var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata);
                    model.Nodes.Add(nodeToAdd);
                }
                node = node.ParentNode;
            }
            model.Nodes.Reverse();

            return model;
        }
开发者ID:noamberda,项目名称:MvcSiteMapProvider,代码行数:36,代码来源:SiteMapPathHelper.cs

示例12: Test_Add_SubCategory_AutoCreateParent

        public void Test_Add_SubCategory_AutoCreateParent()
        {
            SiteMap siteMap = new SiteMap();
            siteMap.UrlCreator = new MockUrlCreator(this);

            // Create the sub node and add it
            SiteMapNode subNode = new SiteMapNode("Category/SubCategory", "SubNode", "TestAction", "TestType");

            // Add the sub node - it should be placed within the sub category
            siteMap.Add(subNode);

            Assert.IsNotNull(siteMap.ChildNodes, "Child nodes collection is null");

            Assert.AreEqual(1, siteMap.ChildNodes.Count, "Wrong number of nodes found.");

            Assert.AreEqual("Category", siteMap.ChildNodes[0].Title, "First level category title is incorrect.");

            Assert.IsNotNull(siteMap.ChildNodes[0].ChildNodes, "Second level child nodes collection is null");

            Assert.AreEqual(1, siteMap.ChildNodes[0].ChildNodes.Count, "Wrong number of second level nodes found.");

            Assert.AreEqual("SubCategory", siteMap.ChildNodes[0].ChildNodes[0].Title, "Second level category title is incorrect.");

            Assert.IsNotNull(siteMap.ChildNodes[0].ChildNodes[0].ChildNodes, "Third level child nodes collection is null");

            Assert.AreEqual(1, siteMap.ChildNodes[0].ChildNodes[0].ChildNodes.Count, "Wrong number of third level nodes found.");
        }
开发者ID:jeremysimmons,项目名称:sitestarter,代码行数:27,代码来源:SiteMapTests.cs

示例13: Test_Add_SubCategory

        public void Test_Add_SubCategory()
        {
            SiteMap siteMap = new SiteMap();
            siteMap.UrlCreator = new MockUrlCreator(this);

            // Create the base node and add it
            SiteMapNode baseNode = new SiteMapNode("Category", "TestUrl");

            List<SiteMapNode> baseNodes = new List<SiteMapNode>();
            baseNodes.Add(baseNode);

            siteMap.ChildNodes = baseNodes;

            // Create the sub category node and add it
            SiteMapNode subCategoryNode = new SiteMapNode("Category", "SubCategory", "TestAction", "TestType");

            List<SiteMapNode> subCategoryNodes = new List<SiteMapNode>();
            subCategoryNodes.Add(subCategoryNode);

            baseNode.ChildNodes = subCategoryNodes;

            // Create the sub node and add it
            SiteMapNode subNode = new SiteMapNode("Category/SubCategory", "SubNode", "TestAction", "TestType");

            // Add the sub node - it should be placed within the sub category
            siteMap.Add(subNode);

            Assert.IsNotNull(subCategoryNode.ChildNodes, "Child nodes collection is null");

            Assert.AreEqual(1, subCategoryNode.ChildNodes.Count, "Wrong number of sub nodes found.");
        }
开发者ID:jeremysimmons,项目名称:sitestarter,代码行数:31,代码来源:SiteMapTests.cs

示例14: SiteMapBase

        /// <summary>
        /// Initializes a new instance of the <see cref="SiteMapBase"/> class.
        /// </summary>
        protected SiteMapBase()
        {
            CacheDurationInMinutes = DefaultCacheDurationInMinutes;
            Compress = DefaultCompress;
            GenerateSearchEngineMap = DefaultGenerateSearchEngineMap;

            RootNode = new SiteMapNode();
        }
开发者ID:vialpando09,项目名称:RallyPortal2,代码行数:11,代码来源:SiteMapBase.cs

示例15: IsModuleActive

 private bool IsModuleActive(SiteMapNode siteMapNode)
 {
     if (SiteMap.CurrentNode != null)
     {
         return SiteMap.CurrentNode.Equals(siteMapNode) || SiteMap.CurrentNode.IsDescendantOf(siteMapNode);
     }
     return false;
 }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:8,代码来源:PublicMaster.master.cs


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