NOTE: This is suggested when you are using ASP.NET, the not Core version. If you are using ASP.NET Core then see the bottom of this article for the recommended approach.
I mounted my own storage to an Azure App Service Web App and I wanted to then have my website direct traffic to that content based on a folder. I followed these instructions to create the mount. The configuration of my mount looked like this.
Figure 1, Mount storage, azure app service, azure files, path mappings
You can view the configuration and the content in the drive via KUDU/SCM. You can find the drive mapping by looking at the environment variables on KUDU, the one you want is named WEBSITE_MOUNT_<NAME>.
Figure 2, Mount storage, azure app service, azure files, path mappings
Initially, what I thought my next step was going to be was to create a virtual directory which points to the Mount path. But when I tried to do that I learned, or relearned that when running app services that the Physical path must be a location within site\.
Figure 3, Physical path must be a location within site\
I worked through many attempts and hacks until I found this approach that worked for me. It uses XML Document Transformation (XDT) to add a virtual directory to IIS that points to the D:\mounts\brainjammer mount. I wrote this article some years ago which describes this in some more details and another example. Making changes to the applicationHost.config on Azure App Service
Here is a copy of the XDT file I used.
Place it into the D:\home\site directory and restart the site. **Warning** be very careful with this, if you make a typo or something, then your site is hosed. I had to delete and recreate my app a few times. You could possibly FTP to the site and remove the XDT file if necessary.
Figure 4, Mount storage, azure app service, azure files, path mappings
When you execute this syntax and view the applicationHost.config file you will see the configuration is applied.
type D:\local\config\applicationHost.config > myAppHostConfig.config
Figure 5, Mount storage, azure app service, azure files, path mappings
Then you can access that address endpoint with the appended virtual directory.
Figure 6, Mount storage, azure app service, azure files, path mappings
NOTES / Comments:
- This solution is probably a work around for a scenario where you cannot perform this in your code. I did not test this, but it seems possible to code your application to do this instead of achieving it from a configuration perspective. But this assumes you are running ASP.NET Core.
- Make sure your Storage Account is in the same region/location as the App Service for performance reasons.
- There are Static Website which allows you to expose the content you might consider that if it works for your scenario
- I did not test this in a scenario in which the instances scale out. There is an ID in the XDT example, you might need to make that dynamic instead of static. XDT has a lot of options