How to do Basecamp-style accounts in Asp.Net Mvc?

前端 未结 3 1491
傲寒
傲寒 2021-02-06 13:30

For an Asp.Net software as a service application, I want to do account based subdomains like Basecamp and the rest of the 37Signals products have. E.g. acme.myapp.com will load

3条回答
  •  天涯浪人
    2021-02-06 13:50

    We use:

    public static string GetSubDomain()
            {
                string subDomain = String.Empty;
    
                if (HttpContext.Current.Request.Url.HostNameType == UriHostNameType.Dns)
                {
                    subDomain = Regex.Replace(HttpContext.Current.Request.Url.Host, "((.*)(\\..*){2})|(.*)", "$2");
                }
    
                if (subDomain.Length == 0)
                {
                    subDomain = "www";
                }
    
                return subDomain.Trim().ToLower();
            }
    

提交回复
热议问题