简体   繁体   中英

Custom domains and SSL in azure

Hi,

I need to create multiple domains in a single web app @ Azure.

How to approach this concept in azure?.

Thanks.

在此处输入图片说明

you should register domains and then go, for example, programmatic way. I would recommend that - below is the snippet of the code (C#) that will add domains to the webapp. But you can add your hostnames using http://portal.azure.com - Settings => Custom domains => Hostnames. (bring external domains).

1) Install the NuGet Web Sites Management Package into your project.

2) Get Azure Publish Settings file (for example, by using Powershell Get-AzurePublishSettingsFile). You will need that later (the value of the management certificate field inside of that file).

2) Instantiate WebSiteManagementClient. That should help with the understanding of the code.

3) Next, the code is below. I just tested and it works. First, it lists the webspaces, then the websites inside of each of webspace, and you should copy and paste the website webspace into the

public const string base64EncodedCertificate = "ManagementCertificateValueFromPublishSettingsFile";
    public const string subscriptionId = "AzureSubscriptionId";

    static SubscriptionCloudCredentials getCredentials()
    {
        return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
    }
    static void Main(string[] args)
    {
        WebSiteManagementClient client = new WebSiteManagementClient(getCredentials());

        WebSpacesListResponse n = client.WebSpaces.List();
        n.Select(p =>
        {
            Console.WriteLine("webspace {0}", p.Name);
            WebSpacesListWebSitesResponse websitesInWebspace = client.WebSpaces.ListWebSites(p.Name,
                  new WebSiteListParameters()
                  {
                  });
            websitesInWebspace.Select(o =>
            {
                Console.Write(o.Name);     

                return o;
            }).ToArray();
            return p;
        }).ToArray();

        Console.ReadLine();
        var configuration = client.WebSites.Get("WebSpaceName", "WebSiteName", new WebSiteGetParameters());

        configuration.WebSite.HostNames.Add("new domain");
        var resp = client.WebSites.Update("WebSpaceName", "WebSiteName", new WebSiteUpdateParameters() { HostNames = configuration.WebSite.HostNames });
        Console.WriteLine(resp.StatusCode);
        Console.ReadLine();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM