Azure CloudBlobContainer.CreateIfNotExists() throw

2019-08-03 19:04发布

I've started getting 403 Error on blobContainer.createIfNotExists. Following is the source code.

 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
        string blobContainerName =string.IsNullOrEmpty(_sessionContext.DomainName) ? "localdevblob": _sessionContext.DomainName.ToLower();
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(blobContainerName);
        container.CreateIfNotExists();

Things verified:

  • container name is lower case & confirms to the standard
  • the local blob storage is accessible in the Storage Explorer and works fine in reading / uploading content
  • connection string is: add key="StorageConnectionString" value="UseDevelopmentStorage=true"

Anticipating that upgrading the library might fix the issue:

  • Upgraded the Storage Emulator to 5.2
  • Upgraded the Nuget package WindowsAzure.Storage to 8.4.0 (it was 8.1.0 earlier but that was already giving error)

The exception screenshot is below:

enter image description here

UPDATE

Apparently, i just downloaded the sample from https://github.com/Azure-Samples/storage-blob-dotnet-getting-started.git and that works too. and when i compared the cloudBlobClient object in my project and the sample project i found that for some strange reason I found that blobClient (in my project) is missing "AuthenticationHandler" and the "Key" which would be causing the issue. But these 2 values are present in the sample project.

enter image description here

1条回答
smile是对你的礼貌
2楼-- · 2019-08-03 20:00

getting 403 Error on blobContainer.createIfNotExists

I created a sample to reproduce the issue on my side, the code works fine with installing WindowsAzure.Storage sdk v8.1.0 to v8.1.4 and v8.4.0.

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

container.CreateIfNotExists();

And I also test the code with WindowsAzure.Storage v7.0.0, it works too.

Besides, some community members report that the WindowsAzure.Storage sdk returns 403 error when do storage operations if ApplicationInsights is installed in project, this SO thread discussed it.

查看更多
登录 后发表回答