简体   繁体   中英

Read configuration settings from azure cloud service with .NET C#

I am searching for a way to read settings from a deployed windows azure cloud service with C#. Is there any Azure SDK available to easily load this values?

Screenshot from Azure Portal to show which settings i want to read:

在此输入图像描述

[EDIT1]

I missed to add that I tried to load the settings from an external application and not from the service it self.

According to your description, I assumed that you could leverage Microsoft Azure Management Libraries to retrieve the configuration settings, you could follow the steps below:

I created a console application and reference the Microsoft Azure Management Libraries , here is the core code:

private static X509Certificate2 GetStoreCertificate(string thumbprint)
{
  List<StoreLocation> locations = new List<StoreLocation>
  { 
    StoreLocation.CurrentUser, 
    StoreLocation.LocalMachine
  };

  foreach (var location in locations)
  {
    X509Store store = new X509Store("My", location);
    try
    {
      store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
      X509Certificate2Collection certificates = store.Certificates.Find(
        X509FindType.FindByThumbprint, thumbprint, false);
      if (certificates.Count == 1)
      {
        return certificates[0];
      }
    }
    finally
    {
      store.Close();
    }
  }
  throw new ArgumentException(string.Format(
    "A Certificate with Thumbprint '{0}' could not be located.",
    thumbprint));
}
static void Main(string[] args)
{
    CertificateCloudCredentials credential = new CertificateCloudCredentials("{subscriptionId}", GetStoreCertificate("{thumbprint}"));
    using (var computeClient = new ComputeManagementClient(credential))
    {
        var result = computeClient.HostedServices.GetDetailed("{your-cloudservice-name}");
        var productionDeployment=result.Deployments.Where(d => d.DeploymentSlot == DeploymentSlot.Production).FirstOrDefault();
    }
    Console.WriteLine("press any key to exit...");
    Console.ReadKey();
}

You could retrieve the configuration settings from productionDeployment.Configuration as follows:

在此输入图像描述

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