How to map an Azure App Service Web App virtual directory to Azure Storage Container

OK, so I tricked you…you can’t do what is said in the title, well I better not say you can’t because someone could possibly come up with a a way, but what I should say is that if you try to create a virtual directory in the portal as shown in Figure 1, that points to an Azure Storage Container, you will get the following error:

Failed to update web app settings for map-vd-storage: {“Code”:”BadRequest”,”Message”:
“The provided directory https://****** is not located within
site\\.”,”Target”:null,”Details”:[{“Message”:”The provided directory
https://******* is not located within site\\.”},
“The provided directory {0} is not located within {1}.”,”Parameters”:[
“The provided directory https://******* is not located within


Figure 1, how to codeless point an Azure Web App to an Azure Storage Container

Instead of trying to do that, you might consider using a URL Rewrite rule as shown here.

         <rule name=”Redirect to storage”>
           <match url=”^images/.*”/>
           <action type=”Redirect” url=”https://***{R:0}” redirectType=”Permanent” />

The URL Rewrite rule is looking for any request that contains ^images/.* in it.  What does the ^ (caret) mean in the URL Rewrite rule?  It means “look at the beginning of the line” when using the caret ( ^ ) the expression needs to be found anywhere in the URL and the .* (dot star) matches zero or more of any character.  If a match is made, then the request is redirected to my Azure Storage container, for example a request made to:

http://? would match the rule and the request would be redirected to https://?

The following HTML code, hosted on an Azure App Service Web App would be redirected to the Azure Storage Container:

     <title>How to redirect a request to an Azure Web App to an Azure Blob Storage Container</title>
     <img src=”https://******” />

This approach does result in a 301, see Figure 2, I did not try to find any way around that, share if you know.  Otherwise, HTH!


Figure 2, how to redirect requests to an Azure Web App to Azure Storage