Search code examples
azureazure-storageazure-blob-storageazure-virtual-machine

CreateIfNotExistsAsync - This request is not authorized to perform this operation


I am using Microsoft sample client app that puts an image in blob storage.

It works on my laptop but when I place it in my Azure VM Windows service I get the following error:

ERROR: This request is not authorized to perform this operation. -    at 
Microsoft.Azure.Storage.Core.Executor.Executor.<ExecuteAsync>d__1`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Storage.Blob.CloudBlobContainer.<CreateAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Storage.Blob.CloudBlobContainer.<CreateIfNotExistsAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

Both ip addresses (laptop and vm) have been added to firewall settings.

I am using the same access key for both. I also tried the second key.

            string containerName = ContainerPrefix + Guid.NewGuid();
        CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString();
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(containerName);
        try
        {
            BlobRequestOptions requestOptions = new BlobRequestOptions() { RetryPolicy = new NoRetry() };
            await container.CreateIfNotExistsAsync(requestOptions, null);
        }
        catch (StorageException ex)
        {
            Console.WriteLine($"ERROR: {ex.Message} - {ex.StackTrace}");
            Console.ReadLine();
            throw;
        }

Thoughts?

Gina


Solution

  • Try Allow access from : All networks to eliminate possibility of IP address issue.

    enter image description here