Azure的API服务器无法进行身份验证请求 [英] Azure API The server failed to authenticate the request

查看:636
本文介绍了Azure的API服务器无法进行身份验证请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任务(我试图与工人的作用,并上传一个控制台应用程序,并运行.exe)应该运行,每天一次,并收集我的一些虚拟机的Azure指标。这完美的作品在本地,但在云服务,我得到这个错误:

I have a task ( I tried with worker role and to upload a console app and run the .exe) that should run once a day and gather Azure Metrics of some of my VMs. This works flawlessly locally but on a cloud service I get this Error:

未处理的异常:Microsoft.WindowsAzure.CloudException:ForbiddenError:服务器无法验证请求。验证证书是否有效以及与此订阅关联。在Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucces ...等。

Unhandled Exception: Microsoft.WindowsAzure.CloudException: ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and associated with this subscription. at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucces ... etc.

在哪里发生这种情况的行是:

The line where this happens is:

MetricDefinitionListResponse metricListResponse = metricsClient.MetricDefinitions.List(resourceId, null,
            nspace);

这是我的code的一部分:

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 have placed the management certificate in my solution, and I load it from there (it is set to always copy) and is the same (and the same way) I use when I run it locally.

那么,什么证是抱怨认证?我似乎无法看到的问题是什么。任何帮助将大大AP preciated因为我已经使用这个整个下午好!

So what "certificate" is it complaining about "to authenticate"? I can't seem to see what the problem is. Any help would be greatly appreciated as I have used the whole afternoon on this!

PS:我已经在提升模式下运行该

PS: I am already running this in elevated mode!

推荐答案

有关其他人可能有这个问题,我已经解决了它作为在底部这里解释:(<一href=\"http://www.dinohy.com/post/2013/11/12/403-Forbidden-when-Use-Azure-Management-REST-API-on-Role-instance.aspx\">http://www.dinohy.com/post/2013/11/12/403-Forbidden-when-Use-Azure-Management-REST-API-on-Role-instance.aspx)

For someone else that may have this issue, I have solved it as explained here in the bottom : (http://www.dinohy.com/post/2013/11/12/403-Forbidden-when-Use-Azure-Management-REST-API-on-Role-instance.aspx)


  1. 下载从publishsettings文件:<一href=\"https://manage.windowsazure.com/publishsettings/index?client=vs&schemaversion=2.0\">https://manage.windowsazure.com/publishsettings/index?client=vs&schemaversion=2.0 (这是一个XML文件,可以用记事本打开它)

  1. Download the publishsettings file from:https://manage.windowsazure.com/publishsettings/index?client=vs&schemaversion=2.0 (This is a XML file, you can open it with notepad)

查找ManagementCertificate属性的值复制到字符串。这为Base64连接codeD字符串,就可以使用这个字符串创建证书:字符串base64Cer =ManagementCertificate的值

Find ManagementCertificate property, copy the value to a string. That a Base64 encoded string, you can use this string create a certificate: string base64Cer="The value of ManagementCertificate "

使用这个字符串创建证书。 VAR证书=新X509Certificate2(base64Cer);

Use this string create a certificate. var certificate = new X509Certificate2(base64Cer);

尽管这最后一步是不完全一样直接传递字符串(作为字符串太长,将导致一个异常),而是如下:
VAR证书=新X509Certificate2(Convert.FromBase64String(base64cer));

although this last step is not exactly like passing the string directly (as the string is too long and will cause an exception) but rather is as follows: var cert = new X509Certificate2(Convert.FromBase64String(base64cer));

希望这会帮助别人在我的位置了。

Hope this will help someone else in my position too.

这篇关于Azure的API服务器无法进行身份验证请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆