Get the root part of a domain in .NET

September 16th, 2011 by Don Leave a reply »

Need to get the .com, .us, .biz, etc. part of the domain name in .NET?

Here’s how:

Dim root As String
root = Right(Request.Url.Host, (Request.Url.Host.Length) - InStrRev(Request.Url.Host, "."))

Advertisement

2 comments

  1. Bill says:

    This would work too:

    Dim root as string = replace(right(request.servervariables(“http_host”),3),”.”,”")

  2. Don says:

    You can’t assume domain names are all 3 characters. Also, why would you replace the “.” in this scenario?

Leave a Reply