繁体   English   中英

无法在存储模拟器上创建Azure Blob容器

[英]Can't create azure blob container on storage emulator

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

我在用:

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

它返回错误Error:

System.AggregateException:发生一个或多个错误。 ---> Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(403)禁止。 ---> System.Net.WebException:远程服务器返回错误:(403)禁止。 在System.Net.HttpWebRequest.GetResponse()

添加以下行:

request.UseDefaultCredentials = true;

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

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

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

您可以在app.config中为存储模拟器设置一个连接字符串:

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM