gpt4 book ai didi

c# - 远程服务器返回错误 : (403) Forbidden on container. CreateIfNotExistsAsync() 方法

转载 作者:行者123 更新时间:2023-12-03 04:35:03 30 4
gpt4 key购买 nike

 static class StorageUtils
{
public static CloudStorageAccount StorageAccount
{
get
{
string account = ConfigurationManager.AppSettings["StorageAccountName"];
//string account = CloudConfigurationManager.GetSetting("StorageAccountName");

//string key = CloudConfigurationManager.GetSetting("StorageAccountAccessKey");
string key = ConfigurationManager.AppSettings["StorageAccountName"];
string connectionString = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", account, key);
return CloudStorageAccount.Parse(connectionString);
}
}
}

我有一个 Web 项目,我将其转换为“MS Azure 云服务项目”

我将 Azure 项目设为默认值并运行 CreateAndConfigureAsync() 来创建容器。它工作正常并在 Azure 存储中创建图像容器。

然后,我将 Web 项目设为默认值,并将 StorageUtils 类中的 CloudConfigurationManager.GetSetting 更改为 ConfigurationManager.AppSettings 并运行 Web 应用项目。然后我收到“远程服务器返回错误:(403) Forbidden”错误container.CreateIfNotExistsAsync() 行被执行。

这是什么原因?

async public void CreateAndConfigureAsync()
{
try
{
CloudStorageAccount storageAccount = StorageUtils.StorageAccount;

// Create a blob client and retrieve reference to images container
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("images");

// Create the "images" container if it doesn't already exist.
if (await container.CreateIfNotExistsAsync())
{
// Enable public access on the newly created "images" container
await container.SetPermissionsAsync(
new BlobContainerPermissions
{
PublicAccess =
BlobContainerPublicAccessType.Blob
});
}
}
catch (Exception ex)
{ }
}

我正在跟踪编码 http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/#upload-blob

最佳答案

从您的第一个代码片段:

string key = ConfigurationManager.AppSettings["StorageAccountName"];

这应该是:

string key = ConfigurationManager.AppSettings["StorageAccountAccessKey"];

关于c# - 远程服务器返回错误 : (403) Forbidden on container. CreateIfNotExistsAsync() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26548304/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com