How to get domain and subdomain name from an url in C#

rohanp
 
on Aug 11, 2016 07:15 AM
16147 Views

How to get subdomain name in codebehind

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 11, 2016 07:16 AM

Hi rohanp,

Refer the below code.

Uri fullPath = new Uri("http://subdomain1.domain.com");
string hostName = fullPath.Host;
string[] domains = hostName.Split(new char[] { '.' });
string subDomain = domains[0];
string domain = domains[1];