【问题标题】:How to add subdomain to Azure WebSite via API如何通过 API 将子域添加到 Azure 网站
【发布时间】:2015-12-19 19:08:26
【问题描述】:

我的网站托管为 Azure 网站,我需要允许用户创建自己的子域。
我已经使用 DNS 和 CNAME 选项在本地机器上实现了这个,但我不能在 Azure 中做到这一点。当我尝试为站点添加 Azure 主机名时,我收到主机名必须以“.azurewebsites.net”结尾的错误。

这是我的代码:

var client = new WebSiteManagementClient(new CertificateCloudCredentials(ConfigurationManager.AppSettings["AzureSubscriptionId"],
                    new X509Certificate2(Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "{certificate}"), "{password}")));

var configuration = client.WebSites.Get(webSpaceName, webSiteName, new WebSiteGetParameters());

if (configuration.StatusCode != HttpStatusCode.OK)
    throw new Exception("AzureGet: " + subdomain);

configuration.WebSite.HostNames.Add(hostName);
var response = client.WebSites.Update(webSpaceName, webSiteName, new WebSiteUpdateParameters());

是否有任何其他方法可以添加自定义主机名,例如“sub.mydomain.net”?

【问题讨论】:

    标签: c# azure dns azure-web-app-service hostname


    【解决方案1】:

    您可以为您的网站使用通配符自定义域名,然后通过检查传入请求的标头(主机或 X-Forwarded-Host)来检查应用程序代码中的主机名。

    即您的域名会将 *.mydomain.net 指向您的 Web 应用程序,然后您的数据库会跟踪用户注册的域,然后您的 Web 应用程序会进行路由。

    【讨论】:

      猜你喜欢
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      相关资源
      最近更新 更多