简体   繁体   English

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

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

I'm unable to create a container while using Azure Storage Emulator from my c# .NET code. 从我的C#.NET代码使用Azure存储模拟器时,无法创建容器。

I am using: 我在用:

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

It return the error Error: 它返回错误Error:

System.AggregateException: One or more errors occurred. System.AggregateException:发生一个或多个错误。 ---> Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (403) Forbidden. ---> Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(403)禁止。 ---> System.Net.WebException: The remote server returned an error: (403) Forbidden. ---> System.Net.WebException:远程服务器返回错误:(403)禁止。 at System.Net.HttpWebRequest.GetResponse() 在System.Net.HttpWebRequest.GetResponse()

Add the following line: 添加以下行:

request.UseDefaultCredentials = true;

This will let the application use the credentials of the logged in user to access the site. 这将使应用程序使用登录用户的凭据来访问站点。 If it's returning 403, clearly it's expecting authentication. 如果返回403,则显然是在等待身份验证。

It's also possible that you (now?) have an authenticating proxy in between you and the remote site. 您(现在?)还可能在您和远程站点之间具有身份验证代理。 In which case, try: 在这种情况下,请尝试:

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

You could set a connection string to the storage emulator in an app.config: 您可以在app.config中为存储模拟器设置一个连接字符串:

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

If you want to connect to storage emulator using account name and key, you would need to provide additional details like different endpoints. 如果要使用帐户名和密钥连接到存储模拟器,则需要提供其他详细信息,例如不同的端点。

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;";

This value is identical to the shortcut shown above, UseDevelopmentStorage=true . 该值与上面显示的快捷方式UseDevelopmentStorage=true

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

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