How to create a sub domain on the fly in IIS Server / ASP.NET project
Step 1: Add following DNS records into your donmain:
example.com IN A XXX.XXX.XXX.XXX
www.example.com IN A XXX.XXX.XXX.XXX
default.example.com IN A XXX.XXX.XXX.XXX
# Wild card DNS record
*.example.com IN CNAME default.example.com
Step 2: Create your website in IIS Server for default.example.com
Step 3: Get your sub domain name in ASP.NET MVC project
var uri = Request.Url;
var fullDomain = uri.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped);
var domainParts = fullDomain
.Split('.') // ["test", "example", "com"]
.Take(1); // ["com", "example"]
var subdomain = String.Join(".", domainParts);