Azure CloudBlobContainer.CreateIfNotExists() throws Forbidden (403) on Local Development

你说的曾经没有我的故事 提交于 2019-12-11 05:27:20

问题


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:

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.


回答1:


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.



来源:https://stackoverflow.com/questions/45964172/azure-cloudblobcontainer-createifnotexists-throws-forbidden-403-on-local-dev

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