azure - 无法在存储模拟器上创建 azure blob 容器

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

在通过我的 C# .NET 代码使用 Azure 存储模拟器时,我无法创建容器。

我正在使用:

var container = serviceClient.GetContainerReference("media");
container.CreateIfNotExists();`

它返回错误错误:

System.AggregateException: One or more errors occurred. ---> Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (403) Forbidden. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse()

最佳答案

添加以下行:

request.UseDefaultCredentials = true;

这将使应用程序使用登录用户的凭据来访问该站点。如果返回 403,显然它正在等待身份验证。

您(现在?)也可能在您和远程站点之间有一个身份验证代理。在这种情况下,请尝试:

request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

您可以将连接字符串设置为 storage emulator在 app.config 中:

<appSettings>
  <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>

如果您想使用帐户名和 key 连接到存储模拟器,则需要提供其他详细信息,例如不同的端点。

var connectionString = @"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
    BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
    TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
    QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;";

此值与上面显示的快捷方式相同,UseDevelopmentStorage=true

关于azure - 无法在存储模拟器上创建 azure blob 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50810317/

相关文章:

Azure - 将 MVC API 和 Web API 部署到 Azure 需要什么

azure - 如何将我的 Azure 表存储数据移动到高级存储帐户?

azure - 使用 Spark 删除 Azure blob 中的文件的更快方法是什么?

java - azure-storage-api java 的 downloadAttributes 上不存在指定的 blob

azure - 批量查询异步复制 Blob Azure API 的状态

azure - 使用azure数据工厂将数据从sql-server提取到azure blob的azure管道中出现问题

azure - 部署的隔离功能应用程序返回 404

php - 运行代码时遇到运行时异常

azure - Azure 是否为 "cloudapp.net"提供 https ?

c# - 使用 SAS 将文件从 Azure Blob 存储下载到浏览器