Getting a StorageException (403: Forbidden) on CloudStorageContainer GetContainerReference method

旧巷老猫 提交于 2019-12-07 02:22:32

问题


I'm running the following code in a unit test against Azure's Storage Emulator and receiving a StorageException when I attempt to create the container:

var connectionString = @"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
var account = CloudStorageAccount.Parse(connectionString);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("my-container");
container.CreateIfNotExists();

The Storage Emulator is running and the Blob service is supposedly running at:

http://127.0.0.1:10000/

The exception is:

Microsoft.WindowsAzure.Storage.StorageException : The remote server returned an error: (403) Forbidden.

Any thoughts? Is this possible from a unit test?


回答1:


Please change your connection string from:

var connectionString = @"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";

to

var connectionString = "UseDevelopmentStorage=true";

That should take care of the problem you're facing.




回答2:


container.SetPermissions(
                    new BlobContainerPermissions
                    {
                        PublicAccess =
                            BlobContainerPublicAccessType.Blob
                    });

When initialize connection. But first, use a Client for Storage and change permission of container using the Client.

Works for me ;)



来源:https://stackoverflow.com/questions/17500433/getting-a-storageexception-403-forbidden-on-cloudstoragecontainer-getcontaine

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