protected virtual void AddNodeInternal(ISiteMapNode node, ISiteMapNode parentNode) { if (node == null) { throw new ArgumentNullException("node"); } lock (this.synclock) { bool urlPrepared = false; bool urlEncoded = false; string url = node.Url; if (!string.IsNullOrEmpty(url)) { if (node.HasAbsoluteUrl()) { // This is an external url, so we will encode it url = urlPath.UrlEncode(url); urlEncoded = true; } if (urlPath.AppDomainAppVirtualPath != null) { if (!urlPath.IsAbsolutePhysicalPath(url)) { url = urlPath.MakeVirtualPathAppAbsolute(urlPath.Combine(urlPath.AppDomainAppVirtualPath, url)); } if (this.urlTable.ContainsKey(url)) { if (urlEncoded) { url = urlPath.UrlDecode(url); } throw new InvalidOperationException(String.Format(Resources.Messages.MultipleNodesWithIdenticalUrl, url)); } } urlPrepared = true; } string key = node.Key; if (this.keyTable.ContainsKey(key)) { throw new InvalidOperationException(String.Format(Resources.Messages.MultipleNodesWithIdenticalKey, key)); } this.keyTable[key] = node; if (urlPrepared) { this.urlTable[url] = node; } if (parentNode != null) { this.parentNodeTable[node] = parentNode; if (!this.childNodeCollectionTable.ContainsKey(parentNode)) { this.childNodeCollectionTable[parentNode] = siteMapChildStateFactory.CreateLockableSiteMapNodeCollection(this); } this.childNodeCollectionTable[parentNode].Add(node); } } }
protected virtual string ResolveVirtualPath(ISiteMapNode node) { var url = node.UnresolvedUrl; if (!urlPath.IsAbsoluteUrl(url)) { return(urlPath.MakeVirtualPathAppAbsolute(urlPath.Combine(urlPath.AppDomainAppVirtualPath, url))); } return(url); }
/// <summary> /// Generates the sitemap index elements. /// </summary> /// <param name="numPages">The number of pages.</param> /// <param name="siteMapUrlTemplate">The site map URL template.</param> /// <returns>The sitemap index elements.</returns> protected virtual IEnumerable <XElement> GenerateSiteMapIndexElements(int numPages, string baseUrl, string siteMapUrlTemplate) { // Generate elements for (int i = 1; i <= numPages; i++) { var combinedPath = urlPath.Combine(urlPath.AppDomainAppVirtualPath, "~/" + siteMapUrlTemplate.Replace("{page}", i.ToString())); var pageUrl = baseUrl + urlPath.MakeVirtualPathAppAbsolute(combinedPath); yield return(new XElement(Ns + "sitemap", new XElement(Ns + "loc", pageUrl))); } }
public ISiteMapNode FindSiteMapNode(string rawUrl) { if (rawUrl == null) { throw new ArgumentNullException("rawUrl"); } rawUrl = rawUrl.Trim(); if (rawUrl.Length == 0) { return(null); } if (urlPath.IsAppRelativePath(rawUrl)) { rawUrl = urlPath.MakeVirtualPathAppAbsolute(rawUrl, "/"); } if (this.urlTable.ContainsKey(rawUrl)) { return(this.ReturnNodeIfAccessible(this.urlTable[rawUrl])); } return(null); }