protected internal override void AddNode(SiteMapNode node, SiteMapNode parentNode)
 {
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     if (parentNode == null)
     {
         throw new ArgumentNullException("parentNode");
     }
     SiteMapProvider provider = node.Provider;
     SiteMapProvider provider2 = parentNode.Provider;
     if (provider != this)
     {
         throw new ArgumentException(System.Web.SR.GetString("XmlSiteMapProvider_cannot_add_node", new object[] { node.ToString() }), "node");
     }
     if (provider2 != this)
     {
         throw new ArgumentException(System.Web.SR.GetString("XmlSiteMapProvider_cannot_add_node", new object[] { parentNode.ToString() }), "parentNode");
     }
     lock (base._lock)
     {
         this.RemoveNode(node);
         this.AddNodeInternal(node, parentNode, null);
     }
 }
        //public List<UrlUser> lu = new List<UrlUser>();
        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            if (node.Description.ToLower() == "invisible") return false;

            if (node.Key.ToLower() == "/default.aspx") return true;
            if (UserHelper.IsSysAdmin || string.IsNullOrEmpty(node.Url)) return true;

            List<UrlUser> lu = (List<UrlUser>)HttpContext.Current.Session["IsAccessibleToUser"];
            if (lu == null)
            {
                lu = new List<UrlUser>();
                bool res = !Security.IsDeniedURL(node.Url, UserHelper.DealerCode);
                lu.Add(new UrlUser { res = res, Url = node.Url, DealerCode = UserHelper.DealerCode });
                HttpContext.Current.Session["IsAccessibleToUser"] = lu;
                return res;
            }
            else
            {
                var q = lu.Where(l => l.Url == node.Url && l.DealerCode == UserHelper.DealerCode);
                UrlUser uu = new UrlUser();
                if (q.Count() > 0)
                    uu = q.First();
                else
                    uu = null;
                if (uu != null)
                    return uu.res;
                else
                {
                    bool res = !Security.IsDeniedURL(node.Url, UserHelper.DealerCode);
                    lu.Add(new UrlUser { res = res, Url = node.Url, DealerCode = UserHelper.DealerCode });
                    HttpContext.Current.Session["IsAccessibleToUser"] = lu;
                    return res;
                }
            }
        }
Example #3
0
		public override SiteMapNode BuildSiteMap ()
		{
			if (rootNode == null) {
				rootNode = new SiteMapNode (this, "foo", "~/foo.aspx", "foo", "");
			}
			return rootNode;
		}
        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            if (isRegisterFunctions)
                return true;

            if (!base.IsAccessibleToUser(context, node))
                return false;

            string functionName = node[Resources.PermissionRequiredKey];
            if (functionName == null)
                return true;

            string debug = node["debug"];
            if (debug == "true")
                return true;

            var user = context.User as AccessControlPrincipal;
            if (user != null)
            {
                if (node.Roles.Count > 0)
                {
                    foreach (object obj in node.Roles)
                    {
                        if (user.Roles.Contains(obj.ToString()))
                            return true;
                    }
                }

                return user.CanView(functionName.Trim());
            }

            return false;
        }
Example #5
0
        /// <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;
        }
        public override bool IsAccessibleToUser(System.Web.HttpContext context, System.Web.SiteMapNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (this.SecurityTrimmingEnabled)
            {
                bool   enabled    = false;
                string roleString = node["mcsroles"];
                if (string.IsNullOrEmpty(roleString) == false && ((roleString == "*") || ((context.User != null) && context.User.IsInRole(roleString))))
                {
                    enabled = true;
                    //VirtualPath virtualPath = node.VirtualPath;
                    //return (((virtualPath != null) && virtualPath.IsWithinAppRoot) && Util.IsUserAllowedToPath(context, virtualPath));
                }

                return(enabled);
            }
            else
            {
                return(true);
            }
        }
        private SiteMapNode BuildNodeTree()
        {
            Clear();

            SiteMapNode root = new SiteMapNode(this, "Root", "/", null);
            AddNode(root);

            SPWeb currentsiteRootweb = NCTopMenuHelper.GetCurrentRootWeb();

            SiteMapNode node;

            List<SPWeb> webs = new List<SPWeb>();

            foreach (SPWeb web in currentsiteRootweb.Webs)
            {
                webs.Add(web);
            }

            webs.Sort(new Comparison<SPWeb>(SortWebs));

            foreach (SPWeb web in webs)
            {
                string serverRelativeUrl = "";

                if (web.Webs.Count == 0)
                    serverRelativeUrl = web.ServerRelativeUrl;
                else
                    serverRelativeUrl = getSubsiteUrl(web);

                node = new SiteMapNode(this, web.ID.ToString(), serverRelativeUrl, web.Title);
                AddNode(node, root);
            }

            return root;
        }
        private List <SiteMapUrl> GetSiteMapItems(SiteMapOptions options)
        {
            List <SiteMapUrl> siteMapItems = new List <SiteMapUrl>();

            //first get the ASP.NET SiteMap nodes
            System.Web.SiteMapNode rootNode = System.Web.SiteMap.RootNode;

            //PopulateAspNetSiteMapUrls(siteMapItems, rootNode, options);


            if (options.IncludeCategories)
            {
                PopulateCategoryUrls(siteMapItems, options);
            }

            if (options.IncludeProducts)
            {
                PopulateProductUrls(siteMapItems, options);
            }

            if (options.IncludeWebpages)
            {
                PopulateWebpageUrls(siteMapItems, options);
            }

            return(siteMapItems);
        }
        public override SiteMapNode BuildSiteMap()
        {
            lock(this) {
                Clear();

                var dalc = WebManager.GetService<IDalc>(DalcName);
                var ds = new DataSet();
                dalc.Load(ds, new Query(SourceName));
                rootNode = new SiteMapNode(this, "root", RootUrl, RootTitle);
                var idToNode = new Dictionary<string, SiteMapNode>();

                // build nodes
                foreach (DataRow r in ds.Tables[SourceName].Rows) {
                    var node = CreateNode( r );
                    idToNode[node.Key] = node;
                }
                // set hierarchy relations
                foreach (DataRow r in ds.Tables[SourceName].Rows) {
                    var node = idToNode[ Convert.ToString( r[IdField] ) ];
                    var parentKey = Convert.ToString(r[FkField]);
                    if (r[FkField] != DBNull.Value && idToNode.ContainsKey(parentKey))
                        AddNode(node, idToNode[parentKey]);
                    else
                        AddNode(node, rootNode);
                }

            }
            return rootNode;
        }
Example #10
0
		public void AddNode_Null_2 ()
		{
			var provider = new XmlSiteMapProviderPoker ();
			var node = new SiteMapNode (provider, "/test.aspx");

			provider.DoAddNode (node, null);
		}
Example #11
0
        public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode node)
        {
            PortalSiteMapNode pNode = node as PortalSiteMapNode;

            if (pNode != null)
            {
                if (pNode.Type == NodeTypes.Area)
                {
                    SiteMapNodeCollection nodeColl = new SiteMapNodeCollection();

                    //get and add each node
                    List <MenuItem> menuItems = GetMenuItemsForCurrentUser();
                    //get the top level nodes
                    var topNodes = from m in menuItems where String.IsNullOrEmpty(m.ParentItem) orderby m.SortOrder ascending select m;
                    //add topNodes
                    foreach (MenuItem menu in topNodes)
                    {
                        SiteMapNode cNode = new SiteMapNode(this, menu.Name, menu.URL, menu.Name);
                        cNode.ChildNodes = GetSubNodes(menuItems, menu);
                        nodeColl.Add(cNode);
                    }
                    return(nodeColl);
                }
                else
                {
                    return(base.GetChildNodes(pNode));
                }
            }
            else
            {
                return(new SiteMapNodeCollection());
            }
        }
        /// <exclude />
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            Verify.ArgumentNotNull(node, "node");

            var pageSiteMapNode = (CmsPageSiteMapNode)node;

            var context = HttpContext.Current;

            List<SiteMapNode> childNodes;
            using (new DataScope(pageSiteMapNode.Culture))
            {
                childNodes = PageManager.GetChildrenIDs(pageSiteMapNode.Page.Id)
                    .Select(PageManager.GetPageById)
                    .Where(p => p != null)
                    .Select(p => new CmsPageSiteMapNode(this, p))
                    .OfType<SiteMapNode>()
                    .ToList();
            }

            if (!childNodes.Any())
            {
                return EmptyCollection;
            }

            if (SecurityTrimmingEnabled)
            {
                childNodes = childNodes.Where(child => child.IsAccessibleToUser(context)).ToList();
            }

            return new SiteMapNodeCollection(childNodes.ToArray());
        }
        private SiteMapNode BuildFullMenuStructure(SPWeb currentWeb)
        {
            Clear();

            SiteMapNode root = null;

            SPWeb webSite = SPContext.Current.Site.RootWeb;
            string relativeUrl = webSite.ServerRelativeUrl.ToString();

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite currentsite = new SPSite(webSite.Site.Url);
                SPWeb rootweb = currentsite.OpenWeb(relativeUrl);

                root = new SiteMapNode(this, rootweb.ID.ToString(), rootweb.ServerRelativeUrl, rootweb.Title);

                if (rootweb == currentWeb)
                {
                    SiteMapNode root2 = new SiteMapNode(this, "Root", "/", null);
                    AddNode(root2);

                    string cacheKey = rootweb.ID.ToString();
                    AddMenuToCache(cacheKey, root2);
                }

                foreach (SPWeb web in rootweb.Webs)
                {
                    SiteMapNode node = BuildNodeTree(web);
                    AddNode(node, root);
                }
            });

            return root;
        }
		internal protected override void AddNode (SiteMapNode node, SiteMapNode parentNode)
		{
			if (node == null)
				throw new ArgumentNullException ("node");
			
			lock (this) {
				string url = node.Url;
				if (url != null && url.Length > 0) {
					if (UrlUtils.IsRelativeUrl (url))
						url = UrlUtils.Combine (HttpRuntime.AppDomainAppVirtualPath, url);
					else
						url = UrlUtils.ResolveVirtualPathFromAppAbsolute (url);
					
					if (FindSiteMapNode (url) != null)
						throw new InvalidOperationException ();
				
					UrlToNode [url] = node;
				}
				
				if (FindSiteMapNodeFromKey (node.Key) != null)
					throw new InvalidOperationException (string.Format ("A node with key {0} already exists.",node.Key));
				KeyToNode [node.Key] = node;
				
				if (parentNode != null) {
					NodeToParent [node] = parentNode;
					if (NodeToChildren [parentNode] == null)
						NodeToChildren [parentNode] = new SiteMapNodeCollection ();
					
					((SiteMapNodeCollection) NodeToChildren [parentNode]).Add (node);
				}
			}
		}
        private void BuildMenuRecursive(StringBuilder sb, SiteMapNode node)
        {
            string imgUrl = node["IconUrl"];
            if (!String.IsNullOrEmpty(imgUrl) && imgUrl.StartsWith("~/"))
            {
                imgUrl = imgUrl.Substring(2, imgUrl.Length - 2);
                imgUrl = CommonHelper.GetStoreLocation() + imgUrl;
            }

            string title = HttpUtility.HtmlEncode(!String.IsNullOrEmpty(node["nopResourceTitle"]) ? GetLocaleResourceString(node["nopResourceTitle"]) : node.Title);
            string descr = HttpUtility.HtmlEncode(!String.IsNullOrEmpty(node["nopResourceDescription"]) ? GetLocaleResourceString(node["nopResourceDescription"]) : node.Description);

            sb.Append("<li>");
            sb.AppendFormat("<a href=\"{0}\" title=\"{2}\">{3}{1}</a>", (String.IsNullOrEmpty(node.Url) ? "#" : node.Url), title, descr, (!String.IsNullOrEmpty(imgUrl) ? String.Format("<img src=\"{0}\" alt=\"{1}\" /> ", imgUrl, title) : String.Empty));
            if(node.HasChildNodes)
            {
                sb.Append("<ul>");
                foreach(SiteMapNode childNode in node.ChildNodes)
                {
                    BuildMenuRecursive(sb, childNode);
                }
                sb.Append("</ul>");
            }
            sb.Append("</li>");
        }
Example #16
0
        public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode
                                                            node)
        {
            PortalSiteMapNode pNode = node as PortalSiteMapNode;

            if (pNode != null)
            {
                if (pNode.Type == NodeTypes.Area)
                {
                    SiteMapNodeCollection nodeColl  = base.GetChildNodes(pNode);
                    SiteMapNode           childNode = new SiteMapNode(this,
                                                                      "<http://www.microsoft.com>", "<http://www.microsoft.com>", "Microsoft");

                    SiteMapNode childNode1 = new SiteMapNode(this,
                                                             "<http://support.microsoft.com>", "<http://support.microsoft.com>", "Support");

                    nodeColl.Add(childNode);

                    SiteMapNodeCollection test = new SiteMapNodeCollection();
                    test.Add(childNode1);
                    childNode.ChildNodes = test;

                    return(nodeColl);
                }
                else
                {
                    return(base.GetChildNodes(pNode));
                }
            }
            else
            {
                return(new SiteMapNodeCollection());
            }
        }
Example #17
0
 public static void CheckInstructions(SiteMapNode node, TextWriter report)
 {
   try
   {
     if (node.Url.IndexOf(".wma.") >= 0 || node.Url.EndsWith(".aspx")) return;
     lm_scorm root = LMDataReader.Read(node);
     if (root.template == template_Type.unknown)
     {
       //dumpError(node.Url, report, "Unknown template", null, null);
     }
     else if (root.HasInstruction)
     {
       design_time dsgn = GetTemplateDesignTime(root.template);
       if (dsgn != null)
       {
         if (root.PageInfo.ProdInfo == null)
           throw new Exception("Unknown project in web.config");
         if (root.title == null || (!root.extra_title && !dsgn.TitleOK(root)))
           dumpError(node.Url, report, "Title", root.title, dsgn.AllTitles(root.PageInfo.ProdInfo.Lang));
         foreach (techInstr_Type instr in new techInstr_Type[] { root.instr, root.instr2, root.instr3 })
           if (instr != techInstr_Type.no && !dsgn.instrs.ContainsKey(instr))
             dumpError(node.Url, report, "Instr", instr, dsgn.instrs.Keys);
       }
     }
   }
   catch (Exception e)
   {
     dumpError(node.Url, report, "Cannot read page (" + e.Message + ")", null, null);
   }
   if (node.HasChildNodes)
     foreach (SiteMapNode nd in node.ChildNodes)
       CheckInstructions(nd, report);
 }
Example #18
0
        private SiteMapNode AddNodeRecursive(XmlNode xmlNode, SiteMapNode parent, RequestContext context)
        {
            var routeValues = (from XmlNode attrib in xmlNode.Attributes
                               where !reservedNames.Contains(attrib.Name.ToLower())
                               select new { attrib.Name, attrib.Value }).ToDictionary(x => x.Name, x => (object)x.Value);

            RouteValueDictionary routeDict = new RouteValueDictionary(routeValues);
            VirtualPathData virtualPathData = RouteTable.Routes.GetVirtualPath(context, routeDict);

            if (virtualPathData == null)
            {
                string message = "RoutingSiteMapProvider is unable to locate Route for " +
                                 "Controller: '" + routeDict["controller"] + "', Action: '" + routeDict["action"] + "'. " +
                                 "Make sure a route has been defined for this SiteMap Node.";
                throw new InvalidOperationException(message);
            }

            string url = virtualPathData.VirtualPath;

            string title = xmlNode.Attributes["title"].Value;
            SiteMapNode node = new SiteMapNode(this, Guid.NewGuid().ToString(), url, title);

            base.AddNode(node, parent);

            foreach (XmlNode childNode in xmlNode.ChildNodes)
            {
                AddNodeRecursive(childNode, node, context);
            }

            return node;
        }
Example #19
0
        /// <summary>
        /// XMLSiteMapProvider method override to authenticate nodes that are accessible to user
        /// </summary>
        /// <param name="context"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            bool isAccessable = false;
            if (node.Roles.Count == 0)
            {
                return isAccessable;
            }

            foreach (object role in node.Roles)
            {
                if (role.ToString().Contains('!'))
                {
                    string roleAsString = role.ToString().Substring(1, (role.ToString().Length - 1));
                    if (context.User.IsInRole(roleAsString))
                    {
                        isAccessable = false;
                        break;
                    }
                }
                else
                {
                    if (context.User.IsInRole(role.ToString()))
                    {
                        isAccessable = true;
                        break;
                    }
                    if (role.ToString().Equals("*"))
                    {
                        isAccessable = true;
                        break;
                    }
                }
            }
            return isAccessable;
        }
        //dynamic node creation
        public static Node CreateNodeWithOutChildren(SiteMapNode siteMapNode)
        {
            Node treeNode;

            if (siteMapNode.ChildNodes != null && siteMapNode.ChildNodes.Count > 0)
            {
                treeNode = new Node();
            }
            else
            {
                treeNode = new Node();
                treeNode.Leaf = true;
            }

            if (!string.IsNullOrEmpty(siteMapNode.Url))
            {
                treeNode.Href = siteMapNode.Url.StartsWith("~/") ? siteMapNode.Url.Replace("~/", "http://examples.ext.net/") : ("http://examples.ext.net" + siteMapNode.Url);
            }

            treeNode.NodeID = siteMapNode.Key;
            treeNode.Text = siteMapNode.Title;
            treeNode.Qtip = siteMapNode.Description;

            return treeNode;
        }
Example #21
0
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            List<string> folderPaths = new List<string>();

            if (node.Key == "/" || node is RootNode)
            {
                foreach (var folder in N2.Context.Current.Resolve<IHost>().CurrentSite.UploadFolders)
                {
                    if (!folderPaths.Contains(folder.Path))
                        folderPaths.Add(folder.Path);
                }
                foreach (string folderUrl in N2.Context.Current.EditManager.UploadFolders)
                {
                    if (!folderPaths.Contains(folderUrl))
                        folderPaths.Add(folderUrl);
                }
            }
            else
            {
                foreach(FileData file in FileSystem.GetFiles(node.Url))
                    folderPaths.Add(VirtualPathUtility.ToAppRelative(file.VirtualPath));
                foreach(DirectoryData dir in FileSystem.GetDirectories(node.Url))
                    folderPaths.Add(VirtualPathUtility.ToAppRelative(dir.VirtualPath));
            }

            SiteMapNodeCollection nodes = new SiteMapNodeCollection();
            foreach (string folderPath in folderPaths)
                nodes.Add(NewNode(folderPath));
            return nodes;
        }
        //static node creation with children
        public static Node CreateNode(SiteMapNode siteMapNode)
        {
            Node treeNode = new Node();

            if (!string.IsNullOrEmpty(siteMapNode.Url))
            {

                treeNode.CustomAttributes.Add(new ConfigItem("url", siteMapNode.Url.StartsWith("~/") ? siteMapNode.Url.Replace("~/", "http://examples.ext.net/") : ("http://examples.ext.net" + siteMapNode.Url)));
                treeNode.Href = "#";
            }

            treeNode.NodeID = siteMapNode.Key;
            treeNode.CustomAttributes.Add(new ConfigItem("hash", siteMapNode.Key.GetHashCode().ToString()));
            treeNode.Text = siteMapNode.Title;
            treeNode.Qtip = siteMapNode.Description;

            SiteMapNodeCollection children = siteMapNode.ChildNodes;

            if (children != null && children.Count > 0)
            {
                foreach (SiteMapNode mapNode in siteMapNode.ChildNodes)
                {
                    treeNode.Children.Add(SiteMapModel.CreateNode(mapNode));
                }
            }
            else
            {
                treeNode.Leaf = true;
            }

            return treeNode;
        }
Example #23
0
 /// <summary>
 /// Acquires the roles list from a given <see cref="T:System.Web.SiteMapNode"/>
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="roles">The roles IList to populate.</param>
 protected virtual void AcquireRolesFrom(System.Web.SiteMapNode node, IList <string> roles)
 {
     foreach (var role in node.Roles)
     {
         roles.Add(role.ToString());
     }
 }
        public override SiteMapNode BuildSiteMap()
        {
            lock (this)
            {

                if (!IsInitialized)
                {
                    throw new Exception("BuildSiteMap called incorrectly.");
                }

                if (null == rootNode)
                {
                    // Start with a clean slate
                    Clear();

                    // Select the root node of the site map from Microsoft Access.

                    DataTable table = GetMenuDataSource();

                    if (table.Rows.Count > 0)
                    {
                        rootNode = new SiteMapNode(this, "0");
                        // ����һ�зdz���Ҫ�������ܹ���ȷ��ʾ�˵�
                         AddNode(rootNode,null);
                        BuildSonMenuNode(table, rootNode);
                    }
                    else
                    {
                        return null;
                    }
                }

                return rootNode;
            }
        }
Example #25
0
        // Initialize data structure by reading from xml file
        public override void Initialize(string name, NameValueCollection attributes)
        {
            // If location of sitemap is specified in provider attributes
            if (!string.IsNullOrEmpty(attributes["siteMapFile"]))
            {
                // Set specified sitemap location
                _siteMapPath = attributes["siteMapFile"];
            }

            // Load sitemap file
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(HostingEnvironment.MapPath(_siteMapPath));

            // Create new requestcontext, needed to resolve url's from route values.
            // Current http context is used, route data is cleared.
            _requestContext = new RequestContext(
                new HttpContextWrapper(HttpContext.Current),
                new RouteData()
            );

            // Get nodes recursively
            XmlElement rootElement;

            if ((rootElement = xmlDocument.DocumentElement) == null)
                throw new InvalidOperationException();

            // First child is the sitemap element
            _rootNode = MakeFromNodeRecursively(rootElement, null);

            // Call base because
            // the default implementation initializes the SecurityTrimmingEnabled property for the site map
            // provider from the site navigation configuration.
            base.Initialize(name, attributes);
        }
 private SiteMapNode BuildDesignTimeSiteMapInternal()
 {
     if (this._rootNode == null)
     {
         this._rootNode = new SiteMapNode(this, _rootNodeText + " url", _rootNodeText + " url", _rootNodeText, _rootNodeText);
         this._currentNode = new SiteMapNode(this, _currentNodeText + " url", _currentNodeText + " url", _currentNodeText, _currentNodeText);
         SiteMapNode node = this.CreateNewSiteMapNode(_parentNodeText);
         SiteMapNode node2 = this.CreateNewSiteMapNode(_siblingNodeText1);
         SiteMapNode node3 = this.CreateNewSiteMapNode(_siblingNodeText2);
         SiteMapNode node4 = this.CreateNewSiteMapNode(_siblingNodeText3);
         SiteMapNode node5 = this.CreateNewSiteMapNode(_childNodeText1);
         SiteMapNode node6 = this.CreateNewSiteMapNode(_childNodeText2);
         SiteMapNode node7 = this.CreateNewSiteMapNode(_childNodeText3);
         this.AddNode(this._rootNode);
         this.AddNode(node, this._rootNode);
         this.AddNode(node2, node);
         this.AddNode(this._currentNode, node);
         this.AddNode(node3, node);
         this.AddNode(node4, node);
         this.AddNode(node5, this._currentNode);
         this.AddNode(node6, this._currentNode);
         this.AddNode(node7, this._currentNode);
     }
     return this._rootNode;
 }
		public override SiteMapNode BuildSiteMap ()
		{
			if (root != null)
				return root;
			// Whenever you call AddNode, it tries to find dups, and will call this method
			// Is this a bug in MS??
			if (building)
				return null;
			
			lock (this) {
				try {
					building = true;
					if (root != null)
						return root;
					XmlDocument d = new XmlDocument ();
					d.Load (file);
					
					XmlNode nod = d.DocumentElement ["siteMapNode"];
					if (nod == null)
						throw new HttpException ("Invalid site map file: " + Path.GetFileName (file));
						
					root = BuildSiteMapRecursive (nod);
						
					AddNode (root);
				} finally {
					building = false;
				}
				return root;
			}
		}
Example #28
0
 private void AddSiteMap(SyndicationWriter writer, SiteMapNode node)
 {
     writer.WriteStartElement("sitemap");
     writer.WriteStartElement("loc");
     writer.WriteString(node.Url + "?sitemap");
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node) {
            SiteMapNodeCollection nodes = new SiteMapNodeCollection();

            foreach (string topic in DocSiteNavigator.GetSubTopics(node.Key))
                nodes.Add(CreateSiteMapNode(topic));

            return nodes;
        }
 private SiteMapNode ReturnNodeIfAccessible(SiteMapNode node)
 {
     if (node != null && node.IsAccessibleToUser(HttpContext.Current))
     {
         return node;
     }
     return null;
 }
Example #31
0
 public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode 
 node)
 {
 PortalSiteMapNode pNode = node as PortalSiteMapNode;
 if (pNode != null)
 {
 if (pNode.Type == NodeTypes.Area)
 {
Example #32
0
 protected override void Clear()
 {
     lock (this)
     {
         this._rootNode = null;
         base.Clear();
     }
 }
Example #33
0
        public static mojoSiteMapNode GetCurrentPageSiteMapNode(SiteMapNode rootNode)
        {
            if (rootNode == null) { return null; }
            PageSettings currentPage = CacheHelper.GetCurrentPage();
            if (currentPage == null) { return null; }

            return GetSiteMapNodeForPage(rootNode, currentPage);
        }
 public virtual int Add(SiteMapNode value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return this.List.Add(value);
 }
Example #35
0
		public void Node_equals ()
		{
			SiteMapNode node = new SiteMapNode (new DummyProvider (), "Node", "1", "", null, null, null, null, null);
			SiteMapNode node1 = new SiteMapNode (new DummyProvider (), "Node", "1", "", null, null, null, null, null);
			SiteMapNode node2 = new SiteMapNode (new DummyProvider (), "Node", "2", "", null, null, new NameValueCollection (), null, null);
			Assert.IsTrue (node.Equals (node1), "both nodes have attrib=null");
			Assert.IsFalse (node.Equals (node2), "one node has attrib=null");
		}
 public override SiteMapNode GetParentNode(SiteMapNode node)
 {
     ContentItem item = Context.Persister.Get(int.Parse(node.Key));
     if(item != null && item.Parent != null && !Context.UrlParser.IsRootOrStartPage(item))
         return Convert((ContentItem)item.Parent);
     else
         return null;
 }
Example #37
0
        /// <summary>
        /// Acquires the robots meta values list from a given <see cref="T:System.Web.SiteMapNode"/>
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="roles">The robots meta values IList to populate.</param>
        protected virtual void AcquireMetaRobotsValuesFrom(System.Web.SiteMapNode node, IList <string> metaRobotsValues)
        {
            var values = node.GetAttributeValue("metaRobotsValues").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var value in values)
            {
                metaRobotsValues.Add(value);
            }
        }
Example #38
0
        /// <summary>
        /// Acquires the preserved route parameters list from a given <see cref="T:System.Web.SiteMapNode"/>
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="roles">The preserved route parameters IList to populate.</param>
        protected virtual void AcquirePreservedRouteParametersFrom(System.Web.SiteMapNode node, IList <string> preservedRouteParameters)
        {
            var localParameters = node.GetAttributeValue("preservedRouteParameters").Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var parameter in localParameters)
            {
                preservedRouteParameters.Add(parameter.Trim());
            }
        }
        /// <summary>
        /// Inherits the controller from the parent node if it is not provided in the current <see cref="System.Web.SiteMapNode"/> and the parent node is not null.
        /// </summary>
        /// <param name="node">The siteMapNode element.</param>
        /// <param name="parentNode">The parent node.</param>
        /// <returns>The value provided by either the siteMapNode or parentNode.Controller.</returns>
        protected virtual string InheritControllerIfNotProvided(System.Web.SiteMapNode node, ISiteMapNode parentNode)
        {
            var result = node.GetAttributeValue("controller");

            if (string.IsNullOrEmpty(result) && parentNode != null)
            {
                result = parentNode.Controller;
            }

            return(result);
        }
        /// <summary>
        /// Inherits the area from the parent node if it is not provided in the current <see cref="System.Web.SiteMapNode"/> and the parent node is not null.
        /// </summary>
        /// <param name="node">The siteMapNode element.</param>
        /// <param name="parentNode">The parent node.</param>
        /// <returns>The value provided by either the siteMapNode or parentNode.Area.</returns>
        protected virtual string InheritAreaIfNotProvided(System.Web.SiteMapNode node, ISiteMapNode parentNode)
        {
            var result = node.GetAttributeValue("area");

            // NOTE: Since there is no way to determine if an attribute exists without using reflection,
            // using area="" to override the parent area is not supported.
            if (string.IsNullOrEmpty(result) && parentNode != null)
            {
                result = parentNode.Area;
            }

            return(result);
        }
Example #41
0
        protected virtual void ProcessNodes(ISiteMap siteMap, ISiteMapNode rootNode, System.Web.SiteMapNode providerRootNode)
        {
            foreach (System.Web.SiteMapNode node in providerRootNode.ChildNodes)
            {
                var          childNode  = GetSiteMapNodeFromProviderNode(siteMap, node, rootNode);
                ISiteMapNode parentNode = rootNode;

                siteMap.AddNode(childNode, parentNode);

                // Continue recursively processing
                ProcessNodes(siteMap, childNode, node);
            }
        }
        private void PopulateAspNetSiteMapUrls(List <SiteMapUrl> siteMapItems, System.Web.SiteMapNode siteMapNode, SiteMapOptions options)
        {
            if (siteMapNode == null)
            {
                return;
            }
            string nodeUrl = GetAbsoluteUrl(siteMapNode.Url);

            siteMapItems.Add(new SiteMapUrl(nodeUrl, options.DefaultChangeFrequency, options.DefaultUrlPriority));
            if (siteMapNode.HasChildNodes)
            {
                for (int i = 0; i < siteMapNode.ChildNodes.Count; i++)
                {
                    PopulateAspNetSiteMapUrls(siteMapItems, siteMapNode.ChildNodes[i], options);
                }
            }
        }
Example #43
0
        /// <summary>
        /// Acquires the route values from a given <see cref="T:System.Web.SiteMapNode"/>.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        protected virtual void AcquireRouteValuesFrom(System.Web.SiteMapNode node, IRouteValueDictionary routeValues)
        {
            // Unfortunately, the ASP.NET implementation uses a protected member variable to store
            // the attributes, so there is no way to loop through them without reflection or some
            // fancy dynamic subclass implementation.
            var attributeDictionary = node.GetPrivateFieldValue <NameValueCollection>("_attributes");

            foreach (string key in attributeDictionary.Keys)
            {
                var attributeName  = key;
                var attributeValue = node[key];

                if (reservedAttributeNameProvider.IsRouteAttribute(attributeName))
                {
                    routeValues.Add(attributeName, attributeValue);
                }
            }
        }
Example #44
0
        protected virtual ISiteMapNode GetSiteMapNodeFromProviderNode(ISiteMap siteMap, System.Web.SiteMapNode node, ISiteMapNode parentNode)
        {
            // Use the same keys as the underlying provider.
            string key = node.Key;
            var    implicitResourceKey = node.ResourceKey;

            // Create Node
            ISiteMapNode siteMapNode = siteMapNodeFactory.Create(siteMap, key, implicitResourceKey);

            siteMapNode.Title       = node.Title;
            siteMapNode.Description = String.IsNullOrEmpty(node.Description) ? siteMapNode.Title : node.Description;
            if (this.reflectAttributes)
            {
                AcquireAttributesFrom(node, siteMapNode.Attributes);
            }
            AcquireRolesFrom(node, siteMapNode.Roles);
            siteMapNode.Clickable           = bool.Parse(node.GetAttributeValueOrFallback("clickable", "true"));
            siteMapNode.VisibilityProvider  = node.GetAttributeValue("visibilityProvider");
            siteMapNode.DynamicNodeProvider = node.GetAttributeValue("dynamicNodeProvider");
            siteMapNode.ImageUrl            = node.GetAttributeValue("imageUrl");
            siteMapNode.TargetFrame         = node.GetAttributeValue("targetFrame");
            siteMapNode.HttpMethod          = node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant();
            siteMapNode.Url = node.Url;
            siteMapNode.CacheResolvedUrl = bool.Parse(node.GetAttributeValueOrFallback("cacheResolvedUrl", "true"));
            siteMapNode.CanonicalUrl     = node.GetAttributeValue("canonicalUrl");
            siteMapNode.CanonicalKey     = node.GetAttributeValue("canonicalKey");
            this.AcquireMetaRobotsValuesFrom(node, siteMapNode.MetaRobotsValues);
            siteMapNode.ChangeFrequency  = (ChangeFrequency)Enum.Parse(typeof(ChangeFrequency), node.GetAttributeValueOrFallback("changeFrequency", "Undefined"));
            siteMapNode.UpdatePriority   = (UpdatePriority)Enum.Parse(typeof(UpdatePriority), node.GetAttributeValueOrFallback("updatePriority", "Undefined"));
            siteMapNode.LastModifiedDate = DateTime.Parse(node.GetAttributeValueOrFallback("lastModifiedDate", DateTime.MinValue.ToString()));

            // Handle route details

            // Assign to node
            siteMapNode.Route = node.GetAttributeValue("route");
            if (this.reflectRouteValues)
            {
                AcquireRouteValuesFrom(node, siteMapNode.RouteValues);
            }
            AcquirePreservedRouteParametersFrom(node, siteMapNode.PreservedRouteParameters);
            siteMapNode.UrlResolver = node.GetAttributeValue("urlResolver");

            // Add inherited route values to sitemap node
            foreach (var inheritedRouteParameter in node.GetAttributeValue("inheritedRouteParameters").Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var item = inheritedRouteParameter.Trim();
                if (parentNode.RouteValues.ContainsKey(item))
                {
                    siteMapNode.RouteValues.Add(item, parentNode.RouteValues[item]);
                }
            }

            // Handle MVC details

            // Get area, controller and action from node declaration
            string area       = node.GetAttributeValue("area");
            string controller = node.GetAttributeValue("controller");

            siteMapNode.Area       = area;
            siteMapNode.Controller = controller;

            // Inherit area and controller from parent
            if (parentNode != null)
            {
                if (string.IsNullOrEmpty(area))
                {
                    siteMapNode.Area = parentNode.Area;
                }
                if (string.IsNullOrEmpty(controller))
                {
                    siteMapNode.Controller = parentNode.Controller;
                }
            }

            // Add defaults for area
            if (!siteMapNode.RouteValues.ContainsKey("area"))
            {
                siteMapNode.RouteValues.Add("area", "");
            }

            return(siteMapNode);
        }
Example #45
0
 public virtual bool Contains(SiteMapNode value)
 {
     return(this.List.Contains(value));
 }
 public override int IndexOf(SiteMapNode value)
 {
     return(_internalCollection.IndexOf(value));
 }
        protected virtual ISiteMapNodeToParentRelation GetSiteMapNodeFromProviderNode(System.Web.SiteMapNode node, ISiteMapNode parentNode, ISiteMapNodeHelper helper)
        {
            // Use the same keys as the underlying provider.
            string key = node.Key;
            var    implicitResourceKey = node.ResourceKey;

            // Create Node
            var nodeParentMap = helper.CreateNode(key, parentNode.Key, SourceName, implicitResourceKey);
            var siteMapNode   = nodeParentMap.Node;

            siteMapNode.Title       = node.Title;
            siteMapNode.Description = node.Description;
            if (this.reflectAttributes)
            {
                // Unfortunately, the ASP.NET implementation uses a protected member variable to store
                // the attributes, so there is no way to loop through them without reflection or some
                // fancy dynamic subclass implementation.
                var attributeDictionary = node.GetPrivateFieldValue <NameValueCollection>("_attributes");
                siteMapNode.Attributes.AddRange(attributeDictionary, false);
            }
            siteMapNode.Roles.AddRange(node.Roles);
            siteMapNode.Clickable           = bool.Parse(node.GetAttributeValueOrFallback("clickable", "true"));
            siteMapNode.VisibilityProvider  = node.GetAttributeValue("visibilityProvider");
            siteMapNode.DynamicNodeProvider = node.GetAttributeValue("dynamicNodeProvider");
            siteMapNode.ImageUrl            = node.GetAttributeValue("imageUrl");
            siteMapNode.ImageUrlProtocol    = node.GetAttributeValue("imageUrlProtocol");
            siteMapNode.ImageUrlHostName    = node.GetAttributeValue("imageUrlHostName");
            siteMapNode.TargetFrame         = node.GetAttributeValue("targetFrame");
            siteMapNode.HttpMethod          = node.GetAttributeValueOrFallback("httpMethod", "*").ToUpperInvariant();
            siteMapNode.Url = node.Url;
            siteMapNode.CacheResolvedUrl          = bool.Parse(node.GetAttributeValueOrFallback("cacheResolvedUrl", "true"));
            siteMapNode.IncludeAmbientValuesInUrl = bool.Parse(node.GetAttributeValueOrFallback("includeAmbientValuesInUrl", "false"));
            siteMapNode.Protocol             = node.GetAttributeValue("protocol");
            siteMapNode.HostName             = node.GetAttributeValue("hostName");
            siteMapNode.CanonicalKey         = node.GetAttributeValue("canonicalKey");
            siteMapNode.CanonicalUrl         = node.GetAttributeValue("canonicalUrl");
            siteMapNode.CanonicalUrlProtocol = node.GetAttributeValue("canonicalUrlProtocol");
            siteMapNode.CanonicalUrlHostName = node.GetAttributeValue("canonicalUrlHostName");
            siteMapNode.MetaRobotsValues.AddRange(node.GetAttributeValue("metaRobotsValues"), new[] { ' ' });
            siteMapNode.ChangeFrequency  = (ChangeFrequency)Enum.Parse(typeof(ChangeFrequency), node.GetAttributeValueOrFallback("changeFrequency", "Undefined"));
            siteMapNode.UpdatePriority   = (UpdatePriority)Enum.Parse(typeof(UpdatePriority), node.GetAttributeValueOrFallback("updatePriority", "Undefined"));
            siteMapNode.LastModifiedDate = DateTime.Parse(node.GetAttributeValueOrFallback("lastModifiedDate", DateTime.MinValue.ToString()));
            siteMapNode.Order            = int.Parse(node.GetAttributeValueOrFallback("order", "0"));

            // Handle route details

            // Assign to node
            siteMapNode.Route = node.GetAttributeValue("route");
            if (this.reflectRouteValues)
            {
                // Unfortunately, the ASP.NET implementation uses a protected member variable to store
                // the attributes, so there is no way to loop through them without reflection or some
                // fancy dynamic subclass implementation.
                var attributeDictionary = node.GetPrivateFieldValue <NameValueCollection>("_attributes");
                siteMapNode.RouteValues.AddRange(attributeDictionary);
            }
            siteMapNode.PreservedRouteParameters.AddRange(node.GetAttributeValue("preservedRouteParameters"), new[] { ',', ';' });
            siteMapNode.UrlResolver = node.GetAttributeValue("urlResolver");

            // Add inherited route values to sitemap node
            foreach (var inheritedRouteParameter in node.GetAttributeValue("inheritedRouteParameters").Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var item = inheritedRouteParameter.Trim();
                if (parentNode.RouteValues.ContainsKey(item))
                {
                    siteMapNode.RouteValues.Add(item, parentNode.RouteValues[item]);
                }
            }

            // Handle MVC details

            // Get area and controller from node declaration
            siteMapNode.Area       = this.InheritAreaIfNotProvided(node, parentNode);
            siteMapNode.Controller = this.InheritControllerIfNotProvided(node, parentNode);

            return(nodeParentMap);
        }
        public override bool IsAccessibleToUser(System.Web.HttpContext context, System.Web.SiteMapNode node)
        {
            try
            {
                if (node == null)
                {
                    throw new ArgumentNullException("node");
                }

                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }

                if (!this.SecurityTrimmingEnabled)
                {
                    return(true);
                }

                if ((node.Roles != null) && (node.Roles.Count > 0))
                {
                    foreach (string role in node.Roles)
                    {
                        if (HttpContext.Current.User != null)
                        {
                            MembershipUser user = Membership.GetUser();
                            if (user != null)
                            {
                                if (role == user.UserName)
                                {
                                    return(true);
                                }
                            }
                        }
                        if (role == "*" || role.ToUpper() == SystemSetting.ANONYMOUS_ROLEID.ToUpper())
                        {
                            return(true);
                        }
                        else if (context.User != null)
                        {
                            if (context.User.IsInRole(role))
                            {
                                return(true);
                            }
                        }
                        string[] userRoles = GetUserRoles();
                        for (int i = 0; i < userRoles.Length; i++)
                        {
                            if (role == userRoles[i].ToUpper())
                            {
                                return(true);
                            }
                        }
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Example #49
0
 protected internal virtual void RemoveNode(SiteMapNode node)
 {
     throw new NotImplementedException();
 }
 public override void Remove(SiteMapNode value)
 {
     throw new NotSupportedException(SR.GetString(SR.Collection_readonly));
 }
 public override void Insert(int index, SiteMapNode value)
 {
     throw new NotSupportedException(SR.GetString(SR.Collection_readonly));
 }
Example #52
0
 public SiteMapNodeCollection(SiteMapNode value)
 {
     Add(value);
 }
Example #53
0
 public virtual int IndexOf(SiteMapNode value)
 {
     return(this.List.IndexOf(value));
 }
 SiteMapNode CheckAccessibility(SiteMapNode node)
 {
     return((node != null && IsAccessibleToUser(HttpContext.Current, node)) ? node : null);
 }
 public override bool Contains(SiteMapNode node)
 {
     return(_internalCollection.Contains(node));
 }
        protected virtual IEnumerable <ISiteMapNodeToParentRelation> ProcessNodes(ISiteMapNodeToParentRelation parentNode, System.Web.SiteMapNode providerParentNode, ISiteMapNodeHelper helper)
        {
            var result = new List <ISiteMapNodeToParentRelation>();

            foreach (System.Web.SiteMapNode childNode in providerParentNode.ChildNodes)
            {
                var node = GetSiteMapNodeFromProviderNode(childNode, parentNode.Node, helper);

                result.Add(node);

                // Continue recursively processing
                ProcessNodes(node, childNode, helper);
            }
            return(result);
        }
Example #57
0
 public virtual void Remove(SiteMapNode value)
 {
     this.List.Remove(value);
 }
Example #58
0
 public virtual void Insert(int index, SiteMapNode value)
 {
     this.List.Insert(index, value);
 }
Example #59
0
 public abstract SiteMapNode GetParentNode(SiteMapNode node);
Example #60
0
    /// <summary>
    /// Check Quyền user truy cập từng trang
    /// </summary>
    /// <param name="context"></param>
    /// <param name="node"></param>
    /// <returns></returns>
    public override bool IsAccessibleToUser(System.Web.HttpContext context, System.Web.SiteMapNode node)
    {
        if (node == null)
        {
            throw new System.ArgumentNullException("node");
        }

        if (context == null)
        {
            throw new System.ArgumentNullException("context");
        }

        if (!this.SecurityTrimmingEnabled)
        {
            return(true);
        }
        //add node vao listNode
        if (!ProviderAllNode.Contains(node))
        {
            ProviderAllNode.Add(node.Clone());
        }

        //check thuong tinh visible
        bool isVisible;

        if (bool.TryParse(node["visible"], out isVisible))
        {
            if (isVisible)
            {
                return(false);
            }
        }

        SiteMapNodeCollection lstNode = new SiteMapNodeCollection();

        System.Collections.IList roles = node.Roles;

        System.Security.Principal.IPrincipal user = context.User;

        string strDeny = node["deny"];

        //check deny
        if (strDeny != null)
        {
            string[] lstDeny = strDeny.Split(',');
            for (int i = 0; i < lstDeny.Length; i++)
            {
                if (lstDeny[i].Trim() == "*")
                {
                    return(false);
                }
                if (user != null)
                {
                    if (user.IsInRole(lstDeny[i].Trim()))
                    {
                        return(false);
                    }
                }
                else
                if (lstDeny[i].Trim() == "?")
                {
                    return(false);
                }
            }
        }

        if (roles == null || roles.Count == 0)
        {
            return(true);
        }
        if (user == null)
        {
            return(false);
        }

        foreach (string role in roles)
        {
            if ((role == "*") || user.IsInRole(role))
            {
                return(true);
            }
        }
        return(false);
    }