public void GivenUrlsList_WhenAbsoluteAndValid_ShouldPassValidation(string url) { // Fixture setup // Exercise system // Verify outcome Assert.True(UrlHelpers.IsAbsoluteUrl(url)); }
/// <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); }