无法在存储模拟器上创建 azure blob 容器
Can't create azure blob container on storage emulator
在我的 c# .NET 代码中使用 Azure 存储模拟器时,我无法创建容器。
我正在使用:
var container = serviceClient.GetContainerReference("media");
container.CreateIfNotExists();`
它return错误错误:
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;
您可以在 app.config:
中将连接字符串设置为 storage emulator
<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
。
在我的 c# .NET 代码中使用 Azure 存储模拟器时,我无法创建容器。
我正在使用:
var container = serviceClient.GetContainerReference("media");
container.CreateIfNotExists();`
它return错误错误:
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;
您可以在 app.config:
中将连接字符串设置为 storage emulator<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
。