C# 远程服务器返回一个错误:(403)container.CreateIfNotExistsAsync()方法上禁止
我有一个web项目,并将其转换为MS Azure云服务项目 我将Azure项目设为默认,并运行CreateAndConfigureAsync来创建容器。 它工作正常,并在Azure存储中创建图像容器 然后,我将web项目设置为默认值,并在StorageUtils类中将CloudConfigurationManager.GetSetting更改为ConfigurationManager.AppSettings,然后运行web应用项目。 然后我得到远程服务器返回一个错误:403禁止错误时 container.CreateIfNotExistsAsync行执行 这是什么原因C# 远程服务器返回一个错误:(403)container.CreateIfNotExistsAsync()方法上禁止,c#,azure,azure-storage-blobs,C#,Azure,Azure Storage Blobs,我有一个web项目,并将其转换为MS Azure云服务项目 我将Azure项目设为默认,并运行CreateAndConfigureAsync来创建容器。 它工作正常,并在Azure存储中创建图像容器 然后,我将web项目设置为默认值,并在StorageUtils类中将CloudConfigurationManager.GetSetting更改为ConfigurationManager.AppSettings,然后运行web应用项目。 然后我得到远程服务器返回一个错误:403禁止错误时 conta
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);
}
}
}
我正在跟踪编码
来自您的第一个代码片段:
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)
{ }
}
这应该是:
string key = ConfigurationManager.AppSettings["StorageAccountName"];
您是否在web.config文件中定义了StorageAccountName和StorageAccountAccessKey,是否可以检查它们是否正确?是的,这两个值都是正确的。那么,在上传文件时,文件名的长度是否有任何限制。这意味着Azure为每个文件生成一个url,如果我上载了一个文件名较长的文件,在生成url时会出现问题吗?命名限制可在此处找到:
string key = ConfigurationManager.AppSettings["StorageAccountAccessKey"];