This has answer in other languages/platforms however i could not look for a robust solution in C#. Here I am searching for negligence URL which we use within WHOIS so I am not thinking about sub-domain names, port, schema, etc.

Example 1: kingdom/folder/querystring?key=value => kingdom

Example 2: =>

The end result ought to be the same once the owner in whois is identical so and both fit in with that has the which I am have to extract from the URL.

I desired exactly the same, and so i authored a category that you could copy to your solution. It utilizes a hard coded string variety of tld's.

Console.WriteLine(GetDomain.GetDomainFromUrl("http://world wide"))



Console.WriteLine(GetDomain.GetDomainFromUrl("http://world wide kingdom/path/page.htm"))

results kingdom

As @Pete noted, this can be a tiny bit complicated, but I'll try it out.

Observe that this application must have a complete listing of known TLD's. It may be retrieved from Left removing their email list out of this site being an exercise for that readers.

class Program

Primary(string[] args)

    world wide",

            "world wide",






        foreach (string testCase in testCases)

         => ", testCase, UriHelper.GetDomainFromUri(new Uri("http://" + testCase + "/")))


        /* Produces the next results:

            world wide =>

            world wide =>



            localdomain => localdomain

            localdomain.local => localdomain.local



public static class UriHelper",




            // Complete this list from



    public static string GetDomainFromUri(Uri uri)


    public static string GetDomainFromHostName(string hostName)


    private static int FindMatchingParts(string[] hostNameParts, int offset)

    Consists of(domain.ToLowerInvariant()))

            return (hostNameParts.Length - offset) + 1

        return FindMatchingParts(hostNameParts, offset + 1)


    private static string GetPartOfHostName(string[] hostNameParts, int offset)


        string domain = sb.ToString()

        return domain


The nearest you have access to may be the System.Uri.Host property, which may extract the portion. Regrettably, it's difficult to be aware what exactly may be the "toplevel" area of the host (e.g. kingdom versus

if you want to domain title you'll be able to use URi.hostadress insinternet

if you want the url from content you will want to parse them using regex.