0

Hello i need a way to find out the host part of an url , i've tried

Request.Url.Host.Split('.')

but it doesn't work with url like this:

sub.sub.domain.com

or

www.domain.co.uk

since you can have a variable number of dots before and after the domain

i need to get only "domain"

sparrows81
  • 431
  • 3
  • 6
  • 19

2 Answers2

0

Check out the second answer at Get just the domain name from a URL?

I checked the pastebin link; it's active. I didn't test the code myself, but if it outputs as he describes, you can .split() from there.

Community
  • 1
  • 1
Russell Uhl
  • 4,181
  • 2
  • 18
  • 28
0

If you need to be totally flexibel, you need to make a list of all possible top-level-domains, and try to remove those, with dot, from the end of your string, resulting in

www.domain

or

sub.sub.domain

Then take the last characters after the last dot.

Alexander
  • 2,457
  • 1
  • 14
  • 17