该请求无权执行此操作.Azure blobClient [英] This request is not authorized to perform this operation. Azure blobClient

查看:73
本文介绍了该请求无权执行此操作.Azure blobClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,使用 WindowsAzure.Storage nuget包返回容器列表:

I have the following code to return a list of containers using the WindowsAzure.Storage nuget package:

public static class AzureBlobStorageClient
{
    public static CloudBlobClient GetClient(string AccountName = "foo", string AccountKey = "bar" )
    {
        try
        {

            var connectionString = $"DefaultEndpointsProtocol=https;AccountName={AccountName};AccountKey={AccountKey};EndpointSuffix=core.windows.net";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 10);
            blobClient.DefaultRequestOptions.RetryPolicy = exponentialRetryPolicy;
            return blobClient;
        }
        catch (StorageException ex)
        {
            Console.WriteLine("Error returned from the service: {0}", ex.Message);
            throw;
        }
    }

    public static void DeleteContainer(CloudBlobContainer container)
    {
        var result = container.DeleteIfExistsAsync().Result;
    }

    public static List<CloudBlobContainer> GetContainers()
    {
        var client = GetClient();
        BlobContinuationToken continuationToken = null;
        List<CloudBlobContainer> results = new List<CloudBlobContainer>();
        do
        {
            var response = client.ListContainersSegmentedAsync(continuationToken).Result;
            continuationToken = response.ContinuationToken;
            results.AddRange(response.Results);
        }
        while (continuationToken != null);

        return results;
    }

}

运行此命令时,我在client.ListContainersSegmentedAsync(continuationToken).Result上收到以下错误:

when i run this, i get the following error on client.ListContainersSegmentedAsync(continuationToken).Result :

System.AggregateException:'发生一个或多个错误.(该请求无权执行此操作.)'

System.AggregateException: 'One or more errors occurred. (This request is not authorized to perform this operation.)'

,我看不到如何设置请求的授权.

and I can't see how to set the authorization for the request.

我的问题是如何克服此错误消息

My question is how to get past this error message

推荐答案

感谢@gaurav Mantri提供此答案.

Thanks to @gaurav Mantri for this answer.

问题是我的客户端IP没有添加到存储帐户的防火墙规则中.

The issue was my client IP was not added to the firewall rules for the storage account.

要更改此设置,请转到:

To change this go to :

存储帐户> {yourAccount}>防火墙和虚拟网络

Storage accounts > {yourAccount} > Firewalls and Virtual networks

并添加您的IP地址

这篇关于该请求无权执行此操作.Azure blobClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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