public static string InferBaseUrl(this string absoluteUri, string fromPathInfo = null)
{
if (IsNullOrEmpty(fromPathInfo))
{
fromPathInfo = "/" + (HostContext.Config.HandlerFactoryPath ?? "");
}
else
{
fromPathInfo = fromPathInfo.TrimEnd('/');
if (fromPathInfo.Length == 0)
return null;
}
if (IsNullOrEmpty(absoluteUri))
return null;
var pos = absoluteUri.IndexOf(fromPathInfo, "https://".Length + 1, StringComparison.Ordinal);
return pos >= 0 ? absoluteUri.Substring(0, pos) : absoluteUri;
}