Reputation: 23635
i want to get the domain extention (at least i hope it is called this way) from the site name the user is currently on.
so from www.bbc.co.uk it's co.uk and www.google.com = .com https://stackoverflow.com/questions/ask = .com
etc.
especially the ones with the double name (like co.uk) gives me headaches....
EDIT as i understand from the comments, co.uk is not a top level domain? that makes life easier! EDIT new name (top level domain) in the title
Upvotes: 2
Views: 3391
Reputation: 4275
The PublicSuffix project from mozilla is the solution. It is a maintained list of TLD.
You can use the following nuget package Nager.PublicSuffix.
PM> Install-Package Nager.PublicSuffix
Example
var ruleProvider = new SimpleHttpRuleProvider();
await ruleProvider.BuildAsync();
var domainParser = new DomainParser(ruleProvider);
var domainInfo = domainParser.Parse("sub.test.co.uk");
//domainInfo.Domain = "test";
//domainInfo.Hostname = "sub.test.co.uk";
//domainInfo.RegistrableDomain = "test.co.uk";
//domainInfo.SubDomain = "sub";
//domainInfo.TLD = "co.uk";
Upvotes: 3
Reputation: 273439
It's called a toplevel domain (tld) but for the BBC that's just "uk", not "co.uk".
What you want does not follow a standard so you'll need a table to check 'potential' pseudo-tld's
Upvotes: 3
Reputation: 16035
It's called the Top Level Domain and then there's the first sub-domain, which not everyone uses. It's because the first DNS did reverse entries on the split list, to route faster, so it would've parsed to
uk -> co -> example -> www
Upvotes: 0
Reputation: 575
The .co.uk is the .co subdomain of the .uk tld. This question doesn't make sense in terms of the actual structure of dns.
Upvotes: 2
Reputation: 2413
See this question
Regular expression to retrieve domain.tld
The .NET URI class can also retrieve the hostname, of course.
Upvotes: 1