dotnet-Snippets.com
Snippets: 57 | Registered User: 27 | Visitors online: 16
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Gets the second level domain from URI

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 263

Description:

Gets the second level domain from the given URI

Example:

Uri uri = new Uri("http://blog.jan-welker.de/2008/07/28/DieCommunityTermineImmerImBlick.aspx");
string secondLevelDomain = GetSecondLevelDomain(uri);

The result is: "jan-welker.de"




C#
1
2
3
4
5
6
7
8
9
10
11
/// <summary> 
/// Gets the second level domain. 
/// </summary> 
/// <param name="uri">The URI.</param> 
/// <returns></returns> 
static string GetSecondLevelDomain(Uri uri) 
{ 
	string[] domains = uri.Host.Split(new char[] { '.' }); 
	return (domains[domains.Length - 2] + "." + domains[domains.Length - 1]); 
}


This Snippets could be interesting for you:

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)