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);
}
}
}
I have a web project and I converted it to "MS Azure Cloud Service Project"
I make the Azure project default and run CreateAndConfigureAsync() to create the container. It works fine and creates the images container in Azure storage.
Then I make my web project default and change CloudConfigurationManager.GetSetting
to ConfigurationManager.AppSettings
in StorageUtils class and run the web app project.
Then I get "The remote server returned an error: (403) Forbidden" error when
container.CreateIfNotExistsAsync()
line get executed.
What is the reason for this?
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)
{ }
}
I'm following coding on http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/#upload-blob
StorageAccountName
andStorageAccountAccessKey
in web.config file and can you check if they are proper? – Gaurav Mantri