6

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?

4

2 回答 2

10

请更改您的连接字符串:

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

var connectionString = "UseDevelopmentStorage=true";

那应该可以解决您面临的问题。

于 2013-07-06T07:44:51.633 回答
0
container.SetPermissions(
                    new BlobContainerPermissions
                    {
                        PublicAccess =
                            BlobContainerPublicAccessType.Blob
                    });

初始化连接时。但首先,使用客户端进行存储并使用客户端更改容器的权限。

为我工作;)

于 2016-03-30T18:47:45.427 回答