Fix For 404 ResourceNotFound Error After Uploading To Azure Container

Table of contents

  • Introduction
  • Background
  • Solution for Azure 404 Error
  • Conclusion
  • Your turn. What do you think?

Introduction

Here, in this post, we are going to a see how we can resolve the 404 ResourceNotFound Error after uploading an image to Azure CDN. It is obvious that you may feel very sad when you are unable to see the image you recently uploaded to Azure container. But, you don’t have to worry about it; the fix for this error is very simple and in this post, I am going to show you that. I hope you will like this. Now, let’s begin. You can always find this article in my blog here.

Background

I recently created a new container in my Azure Storage account and uploaded one image in it. When I was opening that image in my browser, I was just getting an error as preceding.

This XML file does not appear to have any style information associated with it. The document tree is shown below.

  1. <Error>  
  2.     <Code>ResourceNotFound</Code>  
  3.     <Message> The specified resource does not exist. RequestId:36bdbcfb-0001-0022-44c6-d60b93000000 Time:2017-05-27T08:55:09.8382429Z </Message>  
  4. </Error>  

I was able to download that image and the problem existed only when I opened it in the browser. Then, I came to know about the Access Policy of Azure containers. Here, we are going to see a bit of introduction to that policy.

Solution for Azure 404 Error

Step 1

Login to the Azure Portal and navigate to your container.

Step 2

Now, click on the three dots (…) and then, open Access Policy.

Step 3

Select the access type you prefer.

Option to see Azure Container Policy

According to Microsoft, Access Policy specifies whether the data in the container may be accessed publicly. By default, container data is private to the account owner. Use ‘Blob’ to allow public read access for blobs. Use ‘Container’ to allow public read and list access to the entire container.

So here, I am going to give the policy as Blob.


Change the Azure Access Policy to Blob

You can always do this with some C# code as well.

  1. public static void SetPublicContainerPermissions(CloudBlobContainer container) {  
  2.     BlobContainerPermissions perm = container.GetPermissions();  
  3.     perm.PublicAccess = BlobContainerPublicAccessType.Blob;  
  4.     container.SetPermissions(perm);  
  5. }  

Here, in the above code example, we are accessing the permissions and assigning the Blob access type. You can use ‘Container’ if you want to limit the access to container. In any case, if you need to remove the permission to anonymous users, you can use BlobContainerPublicAccessType.Off. Once you are done, please reload the URL again in the browser. I am sure you will be able to see your image.

Conclusion

Did I miss anything that you may think was needed? Did you find this post useful? I hope you liked this article. Please share with me your valuable suggestions and feedback.

Your turn!

A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, ASP.NET Forum etc. instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help.