Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Azure开发:禁止错误:服务器无法验证请求_C#_.net_Azure - Fatal编程技术网

C# Windows Azure开发:禁止错误:服务器无法验证请求

C# Windows Azure开发:禁止错误:服务器无法验证请求,c#,.net,azure,C#,.net,Azure,最近,我面临一个Azure身份验证问题,错误消息如下: 其他信息:禁止错误:服务器无法验证请求。请验证证书是否有效并与此订阅关联 以下是代码: private TokenCloudCredentials credentials; public ManagerClient(TokenCloudCredentials credentials) { this.credentials = credentials; }

最近,我面临一个Azure身份验证问题,错误消息如下: 其他信息:禁止错误:服务器无法验证请求。请验证证书是否有效并与此订阅关联

以下是代码:

       private TokenCloudCredentials credentials;

        public ManagerClient(TokenCloudCredentials credentials)
        {
            this.credentials = credentials;
        }


        public void GetHostedServices()
        {
            var computeClient = new Microsoft.WindowsAzure.Management.Compute.ComputeManagementClient(credentials);
            var services = computeClient.HostedServices.List().HostedServices;

            foreach (var service in services)
            {
                Console.WriteLine("ServiceName: " + service.ServiceName);
                Console.WriteLine("Uri: " + service.Uri);
                Console.WriteLine();
            }
        }
        public static TokenCloudCredentials GetCredentials(string subscriptionId = "")
        {
            var token = GetAccessToken();
            if(string.IsNullOrEmpty(subscriptionId))
                subscriptionId = ConfigurationManager.AppSettings["subscriptionId"];
            var credential = new TokenCloudCredentials(subscriptionId, token);

            return credential;
        }
        private static string GetAccessToken()
        {
            AuthenticationResult result = null;

            var context = new AuthenticationContext(string.Format(
              ConfigurationManager.AppSettings["login"],
              ConfigurationManager.AppSettings["tenantId"]));

            result = context.AcquireToken(
              ConfigurationManager.AppSettings["apiEndpoint"],
              ConfigurationManager.AppSettings["clientId"],
              new Uri(ConfigurationManager.AppSettings["redirectUri"]));

            if (result == null)
            {
                throw new InvalidOperationException("Failed to obtain the JWT token");
            }

            return result.AccessToken;
        }
              var credentials = Authorizator.GetCredentials("37a80965-5107-4f9b-91c6-a1198ee40226");
              new ManagerClient(credentials).GetHostedServices();

var computeClient=新的Microsoft.WindowsAzure.Management.Compute.ComputeManagementClient(凭据,新Uri(“”)

默认Uri为: 因此,中国Azure需要更改为:**/management.core.chinacloudapi.cn/