locked
Extract domain names from a list of web site urls RRS feed

  • Question

  • I am working on an asp.net console application. and the console application reads the websites from an external service. but the websites comes with different formats,,, these are samples of the formats:-

    http://www.****.co.uk/ 
    http://www.****.com/global/index.htm 
    https://www.****.com/
    https://****.com/
    www.***.net
    *******.com
    now i need to only extract the domain name from the above urls (i do not need to include http or https or wwww , etc..). so i am not sure which is the best appraoch to do so? i need this as i am using a .netlibrary named https://www.nuget.org/packages/ARSoft.Tools.Net which allow me to get the email hosting company from the website domain name.. but if i apply the above urls i will get errors except for the last url which only include the domain name which i am looking to extract...

    so can anyone advice on this please?

    Thanks

    Monday, December 3, 2018 11:58 AM

All replies

  • See if the following is helpful.

    https://stackoverflow.com/questions/14211973/get-host-domain-from-url

    From the link above

    string host = Request.Url.Host;

    And

    Uri myUri = new Uri("http://www.contoso.com:8080/");   
    string host = myUri.Host;  // host is "www.contoso.com"
    Uri.GetLeftPart( UriPartial.Authority )



    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, December 3, 2018 1:02 PM
  • UrlGetPartW does this, but only for the 4 first ones in your sample (when there is http inside)


    Monday, December 3, 2018 1:03 PM
  • Hi johnjohn11,

    Is there any updated, do you try the solution that Karen mentioned.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 12, 2018 7:29 AM