I have a task (I tried with the role of the executor and downloaded the console application and ran .exe), which should run once a day and collect Azure Metrics from some of my virtual machines. This works flawlessly locally, but on the cloud service, I get this error:
Unhandled exception: Microsoft.WindowsAzure.CloudException: ForbiddenError: the server was unable to authenticate the request. Verify that the certificate is valid and associated with this subscription. at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucces ... etc.
The line in which this occurs:
MetricDefinitionListResponse metricListResponse = metricsClient.MetricDefinitions.List(resourceId, null, nspace);
This is part of my code:
string subscriptionId = "fc4xxxx5-835c-xxxx-xxx-xxxxxxx"; // The thumbprint of the certificate. string thumbprint = "βf5 b4 xxxxxxxx f7 c2"; // Get the certificate from the local store. //X509Certificate2 cert = GetCertificate(StoreName.My, StoreLocation.LocalMachine, thumbprint); //cert = GetCertificate(StoreName.My, StoreLocation.CurrentUser, thumbprint) ?? new X509Certificate2(("manageAzure.cer")); var cert = new X509Certificate2(("manageAzure.cer")); Console.WriteLine("Certificate is : " + cert); // Create the metrics client. var metricsClient = new MetricsClient(new CertificateCloudCredentials(subscriptionId, cert)); Console.WriteLine("metricsClient is : " + metricsClient); // The cloud service name and deployment name, found in the dashboard of the management portal. string cloudServiceName = "abms2-carlsberg"; string deploymentName = "abms2-carlsberg"; // Build the resource ID string. string resourceId = ResourceIdBuilder.BuildVirtualMachineResourceId(cloudServiceName, deploymentName); string nspace = "WindowsAzure.Availability"; // Get the metric definitions. MetricDefinitionListResponse metricListResponse = metricsClient.MetricDefinitions.List(resourceId, null, nspace);
I placed the management certificate in my solution and I download it from there (it is always copied) and the same (and the same) that I use when I run it locally.
So, what kind of "certificate" does he complain about "authentication"? I donβt seem to understand what the problem is. Any help would be greatly appreciated as I have been using this whole day on this!
PS: I am already running this in high mode!
c # certificate azure x509 certificate azure-worker-roles
Manuel maestrini
source share