I have a .net site and couple of domains with wildcard dns pointing to it. I use pseudo subdomain system where i extract subdomain name from url with below code
public static string GetSubdomain()
{
string domain = HttpContext.Current.Request.Url.Host;
if (domain.Substring(0, 4).ToLower() == "www.") // if www exists in the url such as www.subdomain.acme.com
domain = domain.Remove(0, 4);
return domain;
}
Code has some limitations. I can not allow users to create sites like subdomain.subdomain.domain.com but subdomain.domain.com.
Due to differend tlds i use (such as site.net, site.mobi, site.co.uk) i couldn't find a solid way to have subdomains with . in it.
Anyone have a snippet where i can use?