Azure网站扩展

我可以使用Azure管理库扩展azure web apps / api应用程序吗?我基本上想要实现扩展和缩小Web应用程序来处理限制 . 因此,我需要通过C#代码扩展Web应用程序和api应用程序 . 任何apprpriate库/ ReST API的指针?

在下面提到的答案的帮助下,我了解如何更新APP服务计划以扩展,但是,我无法找到我的APP服务的webHostingPlanName . 我尝试使用下面的代码,托管计划总是出现空 .

var regionName = "myregion";

        var credentials = GetCredentials();

        var websiteManagementClient = CloudContext.Clients.CreateWebSiteManagementClient(credentials);

        var webSpaces = websiteManagementClient.WebSpaces.List();
        var webSpace = webSpaces.FirstOrDefault(x => x.GeoRegion == regionName);
        if (webSpace == null)
        {
            throw new Exception(string.Format("No webspace for region {0} found", regionName));
        }

        var webHostingPlans = websiteManagementClient.WebHostingPlans.List(webSpace.Name);
        var webHostingPlan = webHostingPlans.FirstOrDefault();// this is null always, I know an APP service exists in this region

回答(1)

2 years ago

是的,我们可以使用Microsoft.WindowsAzure.Management.Websites库来扩展和缩小Web应用程序 . 使用方法 WebSiteManagementClient.WebHostingPlans.UpdateAsync(webspaceName, webHostingPlanName, webHostingPlanUpdateParameters) 来实现它 .

我做了一个演示来完成这个 . 以下是我的详细步骤:

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

2.Create the WebsiteManagementClient object .

我使用cert来创建websitemagement客户端 .

  • 安装VS后,在VS文件夹下创建一个带有makecert.exe的证书 .
makecert -sky exchange -r -n "CN=[CertificateName]" -pe -a sha1 -len 2048 -ss My "[CertificateName].cer

enter image description here

  • 上传 . 然后,Azure门户的Cert文件获取指纹

enter image description here
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);

注意:如果您尝试在Azure上运行该项目 . 请参阅Azure网站应用程序中的使用证书文档 . 添加名为WEBSITE_LOAD_CERTIFICATES的应用程序设置,其值设置为证书的指纹将使您的Web应用程序可以访问它