This request is not authorized to perform this operation. Azure blobClient

喜你入骨 提交于 2020-12-29 05:56:15

问题


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;
    }

}

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

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


回答1:


Thanks to @gaurav Mantri for this answer.

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

To change this go to :

Storage accounts > {yourAccount} > Firewalls and Virtual networks

and add your IP address



来源:https://stackoverflow.com/questions/56130784/this-request-is-not-authorized-to-perform-this-operation-azure-blobclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!