示例#1
0
        public static string GetDomainName(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            if (url.StartsWith("."))
            {
                url = url.Remove(0, 1);
            }
            if (!url.Contains("www."))
            {
                url = "www." + url;
            }
            if (!url.Contains("://"))
            {
                url = "http://" + url;
            }
            var host = new System.Uri(url).Host;

            return(host.Substring(host.LastIndexOf('.', host.LastIndexOf('.') - 1) + 1));
        }