【问题标题】:Getting a StorageException (403: Forbidden) on CloudStorageContainer GetContainerReference method在 CloudStorageContainer GetContainerReference 方法上获取 StorageException(403:禁止)
【发布时间】:2013-07-04 05:43:36
【问题描述】:

我在针对 Azure 的存储模拟器的单元测试中运行以下代码,并在尝试创建容器时收到 StorageException:

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();

存储模拟器正在运行,并且 Blob 服务应该在以下位置运行:

http://127.0.0.1:10000/

例外是:

Microsoft.WindowsAzure.Storage.StorageException : 远程服务器 返回错误:(403) Forbidden。

有什么想法吗?这可能来自单元测试吗?

【问题讨论】:

    标签: azure azure-blob-storage azure-storage-emulator


    【解决方案1】:

    请更改您的连接字符串:

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

    var connectionString = "UseDevelopmentStorage=true";
    

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

    【讨论】:

    • 如果其他人看到这个,身份验证错误可能会误导。在我的情况下,由于使用反斜杠而不是正斜杠,我遇到了这种错误。
    • 在 SDK 2.2 下,该连接字符串返回 400(错误请求)错误。这应该适用于 2.2 吗?
    【解决方案2】:
    container.SetPermissions(
                        new BlobContainerPermissions
                        {
                            PublicAccess =
                                BlobContainerPublicAccessType.Blob
                        });
    

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

    为我工作;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多