none
How To: Display a custom webpage instead of HTTP Errors when the Storage Account's Container is in the private mode (Off) ?

    Question

  • Hi Forum,

    I have created a storage account e.g. (http://MyStorageAccount.blob.core.windows.net/), and inside it I have created a container e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/).

    I uploaded a few HTML pages inside that container e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/Page1.HTML), (http://MyStorageAccount.blob.core.windows.net/MyContainer/Page2.HTML), (http://MyStorageAccount.blob.core.windows.net/MyContainer/Page3.HTML).

    I created a custom domain and mapped it correctly with my blobs. Which means: I can access/view all the HTML pages perfectly using the URLs:

    (http://www.WebSite.com/MyContainer/Page1.HTML), (http://www.WebSite.com/MyContainer/Page2.HTML), (http://www.WebSite.com/MyContainer/Page3.HTML).


    Later on, I was requested to make the container and its content (Blobs) private. So, I used:

    ... permissions.PublicAccess = BlobContainerPublicAccessType.Off

    And it worked perfectly, It made the container and its content (Blobs) private and NOT accessible/viewable.

    So, Whenever The container is in the private mode (Off), and a user tries to view a blob e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/Page1.HTML) or (http://www.WebSite.com/MyContainer/Page1.HTML), The user will always get: HTTP 404 Not Found (The webpage cannot be found).

    My question is: Is there any way that I can display a custom html page displaying a message like: "Sorry, The site is not available now!", Whenever The container is in the private mode ?

    In other words, If my container is in private mode (Off), it means nothing is accessible at all. So, My question is: Can I display a user-friendly web page ("Sorry, The site is not available now!") to users instead of the default HTTP 404 Not Found (The webpage cannot be found) ?

    I have already tried:
    <httpErrors errorMode="Custom">
      <clear />
      <error statusCode="401" path="/error/notallowed" responseMode="ExecuteURL" />
      <error statusCode="403" path="/error/notallowed" responseMode="ExecuteURL" />
      <error statusCode="404" path="/error/notfound" responseMode="ExecuteURL" />
      <error statusCode="500" path="/error/servererror" responseMode="ExecuteURL" />
    </httpErrors>

    But it didn't work :( 


    So, How to offer a better user experience to end-users and NOT letting them see the default confusing HTTP 404 Not Found (The webpage cannot be found).

    Could you please let me know how to implement it?

    Thank you kindly, and I would greatly appreciate your creative inputs !
    Wednesday, September 11, 2013 7:01 PM

Answers

  • HI

    I think the you shouldn't provide the directly url to user(http://MyStorageAccount.blob.core.windows.net/MyContainer/MyImage.png), because this blob is host in Azure storage. You can't add any httpmodule to that.

    You can provide the url like this:

    http://yourwebsite.com/MyContainer/MyImage.png

    then in you have a lot of choice to do that.

    For example:

     StorageCredentials cred = new StorageCredentials("account", "adf0Qd+asf8uvw35fSbja1KeymLkqYSLNYbYxfjNK48N1gqnJ2LrrrIHOw7JWV+soS59VezQ==");
                CloudStorageAccount account = new CloudStorageAccount(cred, false);
                CloudBlobClient blobClient = account.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference("batcontainer");//You can get this value from request url
                container.BeginGetPermissions(ar =>
                {
                    var result = container.EndGetPermissions(ar);
                    if (result.PublicAccess == BlobContainerPublicAccessType.Off)
                    {
                        //Response.Redirect("Your custom html");
                    }
                }, null);
            }


    Please mark post as answered if it helped!

    Wednesday, September 11, 2013 4:31 AM

All replies

  • Hi Forum,

    I have created a storage account e.g. (http://MyStorageAccount.blob.core.windows.net/), and inside it I have created a container e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/).

    I uploaded an image inside that container e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/MyImage.png), and I can access/view the image perfectly.

    Later on, I was asked to make the container and its content (Blobs) private. So, I used:

    ... permissions.PublicAccess = BlobContainerPublicAccessType.Off

    And it worked perfectly and it made the container and its content (Blobs) private and NOT accessible/viewable.

    So, Whenever The container is in the private mode (Off), and a user tries to view a blob e.g. (http://MyStorageAccount.blob.core.windows.net/MyContainer/MyImage.png), The user will always get: HTTP 404 Not Found (The webpage cannot be found).


    My question is: Is there any way that I can display a custom html page displaying a message like: "Sorry, The site is not available now!", Whenever The container is in the private mode ?

    In other words, If my container is in private mode (Off), it means nothing is accessible at all. So, My question is: Can I display a user-friendly web page ("Sorry, The site is not available now!") to users instead of the default HTTP 404 Not Found (The webpage cannot be found) ?

    The idea is to offer a better user experience to end-users and NOT letting them see the default confusing HTTP 404 Not Found (The webpage cannot be found).


    If this is possible, Could you please let me know how to implement it?

    Thank you kindly, and I would greatly appreciate your inputs !

    Tuesday, September 10, 2013 11:45 AM
  • HI

    I think the you shouldn't provide the directly url to user(http://MyStorageAccount.blob.core.windows.net/MyContainer/MyImage.png), because this blob is host in Azure storage. You can't add any httpmodule to that.

    You can provide the url like this:

    http://yourwebsite.com/MyContainer/MyImage.png

    then in you have a lot of choice to do that.

    For example:

     StorageCredentials cred = new StorageCredentials("account", "adf0Qd+asf8uvw35fSbja1KeymLkqYSLNYbYxfjNK48N1gqnJ2LrrrIHOw7JWV+soS59VezQ==");
                CloudStorageAccount account = new CloudStorageAccount(cred, false);
                CloudBlobClient blobClient = account.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference("batcontainer");//You can get this value from request url
                container.BeginGetPermissions(ar =>
                {
                    var result = container.EndGetPermissions(ar);
                    if (result.PublicAccess == BlobContainerPublicAccessType.Off)
                    {
                        //Response.Redirect("Your custom html");
                    }
                }, null);
            }


    Please mark post as answered if it helped!

    Wednesday, September 11, 2013 4:31 AM