连接到Azure存储帐户时收到404错误连接到、帐户、错误、Azure

2023-09-05 03:50:06 作者:跟紧步伐

我要通过教程斑点在这里找到Azure存储帐户 Azure存储教程

I am going through the tutorial for blobs with azure storage accounts found here Azure Storage Tutorial

我已经创建了在Azure上的存储帐户,它说,它是由。 我复制了钥匙和帐户名称为我的配置文件。 我已验证我的应用程序的端点地址的一个在我的Azure存储帐户相匹配。 但是当我运行code,我收到了404错误。 当我复制和过去的从我的蔚蓝帐户的端点地址到浏览器中我也得到一个404错误

I have created the storage account on azure and it says it is up. I have copied the key and account name to my config file. I have verified the endpoint address in my application matches the one on my azure storage account. but when I run the code I get a 404 error. And when I copy and past the endpoint address from my azure account into a browser I also get a 404 error

在这里,我的code。从教程中,我做了添加正确的帐户名和关键配置字符串实际复制的,但把他们赶走了这个帖子

here I the code. actually copied from the tutorial I did add the correct account name and key to the config string but removed them for this post

    // Retrieve storage account from connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

        // Create the blob client.
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve reference to a previously created container.
        CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

        // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

        // Create or overwrite the "myblob" blob with contents from a local file.
        using (var fileStream = System.IO.File.OpenRead(@"myfile"))
        {
            blockBlob.UploadFromStream(fileStream);
        }

和连接字符串

<appSettings>
    <add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myAccount;AccountKey=mykey" />
</appSettings>

任何想法,为什么?我需要做更多的事情在Azure中?

Any ideas why? Do I need to do something more in Azure?

推荐答案

在该容器未创建问题或已被删除。我加了

The problem was the container was not created or had been deleted. I added

container.CreateIfNotExist();

container.CreateIfNotExist();

和它工作得很好。我会期待一个不同的错误不是404而是固定它。

and it worked fine. I would have expect a different error not a 404. but that fixed it.