Azure website scaling

前端 未结 1 1844
小鲜肉
小鲜肉 2020-12-18 16:01

Can I scale azure web apps/api apps using Azure Management libraries? I basically want to implement scaling up and down of web apps to handle throttling. Hence, I need to sc

相关标签:
1条回答
  • 2020-12-18 17:07

    Yes, We can use Microsoft.WindowsAzure.Management.Websites library to scale up and down of web apps. Using method WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters) to implement it.

    I had done a demo to do this. The following are the my detail steps:

    1.Install the Microsoft.WindowsAzure.Management.WebSites that we can get it from the link.

    2.Create the WebsiteManagementClient object.

    I used the cert to create the websitemagement client.

    • Create a cert with makecert.exe that is under the VS folder after install the VS.

      makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer
      

    • Upload the. Cert file to Azure portal then get the thumbprint

    3. Using the code to generate the WebsiteManagementClient object

              public static X509Certificate2 GetCert(string thumbprint)
        {
    
            X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            certStore.Open(OpenFlags.ReadOnly);
       X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
            if (certCollection.Count <= 0) return null;
            X509Certificate2 cert = certCollection[0];
            return cert;
        }
    

    var cert = GetCert(string thumbprint) var subscriptionId ="Your subscriptionId" var webSiteManagementClient = new WebSiteManagementClient(new CertificateCloudCredentials(subscriptionId, cert));

    4.Construct the WebHostingPlanUpdateParameters

    var webHostingPlanUpdateParameters = new WebHostingPlanUpdateParameters
                    {
                        NumberOfWorkers = 1, //the number of the instances
                        SKU = SkuOptions.Standard, 
                        WorkerSize = WorkerSizeOptions.Small
                    };
    

    5.Update the WebHostingPlans with code

    client.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters);
    

    Note: If you try to run the project on the Azure. Please refer to document Using Certificates in Azure Websites Applications. Adding an app setting named WEBSITE_LOAD_CERTIFICATES with its value set to the thumbprint of the certificate will make it accessible to your web application

    0 讨论(0)
提交回复
热议问题