/// <summary> /// Resolve url on sitemap node /// </summary> /// <param name="siteMapNode"></param> /// <returns></returns> public static string ResolveUrl(this SiteMapNode siteMapNode) { var httpContext = HttpContext.Current; var httpContextBase = new HttpContextWrapper(httpContext); return(siteMapNode.ResolveUrl(httpContextBase)); }
/// <summary> /// Determines if node url is within the application or external /// </summary> /// <param name="siteMapNode"></param> /// <param name="httpContext"></param> /// <returns></returns> public static bool HasExternalUrl(this SiteMapNode siteMapNode, HttpContextBase httpContext) { string url; if (!string.IsNullOrEmpty(siteMapNode.Url)) { url = siteMapNode.Url; } else { url = siteMapNode.Url = siteMapNode.ResolveUrl(httpContext); } if (!UrlHelpers.IsAbsoluteUrl(url)) { return(false); } Uri uri = null; if (Uri.TryCreate(url, UriKind.Absolute, out uri)) { var publicFacingUrl = UrlHelpers.GetPublicFacingUrl(httpContext); var isDifferentHost = !uri.Host.Equals(publicFacingUrl.Host, StringComparison.InvariantCultureIgnoreCase); var isDifferentVirtualApplication = !uri.AbsolutePath.StartsWith(httpContext.Request.ApplicationPath, StringComparison.InvariantCultureIgnoreCase); return(isDifferentHost || isDifferentVirtualApplication); } return(false); }
private void ResolveUrl(SiteMapNode rootNode) { rootNode.Url = rootNode.ResolveUrl(); if (rootNode.HasChildNodes) { foreach (var node in rootNode.ChildNodes) { ResolveUrl(node); } } }