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

on Aug 11, 2016 07:15 AM

How to get subdomain name in codebehind

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

Hi rohanp,

Refer the below code.

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