/// <summary> /// Method to determine if string is a local url /// </summary> /// <param name="request">this HttpRequest</param> /// <param name="url">string</param> /// <returns>bool</returns> /// <method>IsLocalUrl(this HttpRequest request, string url)</method> public static bool IsLocalUrl(this HttpRequest request, string url) { if (string.IsNullOrEmpty(url)) { return(false); } Uri absoluteUri; if (Uri.TryCreate(url, UriKind.Absolute, out absoluteUri)) { return(String.Equals(request.GetUri().Host, absoluteUri.Host, StringComparison.OrdinalIgnoreCase)); } else { bool isLocal = !url.StartsWith("http:", StringComparison.OrdinalIgnoreCase) && !url.StartsWith("https:", StringComparison.OrdinalIgnoreCase) && Uri.IsWellFormedUriString(url, UriKind.Relative); return(isLocal); } }