Now we need to tell IIS exactly where to serve files from. To do that, create a virtual directory under the target site. For example:
- alias: files
- physical path: \\mystorageaccount.file.core.windows.net\myfileshare\documents
After that, the URL to a file will look something like this:
https://example.com/files/test.pdfFrom a technical perspective, this is already almost the entire solution. But in practice, this is usually the stage where the main issue appears: IIS cannot read the network path.
Why a mapped drive is not enoughThis is the key point of the whole article. When you connect an Azure File Share via New-PSDrive -Persist or through Explorer, you do it in the context of a specific user. Typically, that is the administrator who is currently logged into the server. IIS does not run under that user. By default, the application typically runs under ApplicationPoolIdentity, meaning a separate service identity such as:
IIS AppPool\MyApplicationPoolThat leads to the classic situation: everything is visible in Explorer, but through the site you get a 401, a 500, or an error accessing the physical path of the virtual directory. That is why, for network resources in IIS, two approaches usually work:
- Specify a UNC path and configure Connect as... with a specific user.
- Or run the application pool under a separate account in whose context the Azure Files credentials are stored.
Here I will follow the first option. For migrating an existing application, it is usually the most practical one: the file model barely changes, and the main pain is reduced to the UNC path, permissions, and the account IIS actually uses to access the share.
Step 4. Configure a user for access to the Azure File ShareOne workable option is to create a separate local user on the virtual machine that IIS will use to access the network folder. For example:
iis-files-userYou can create it through Computer Management, or via PowerShell:
New-LocalUser -Name "iis-files-user" -Password (Read-Host -AsSecureString "Enter password") -FullName "IIS Files User" -Description "User for IIS access to Azure File Share"
After that, the user must have credentials for access to the Azure File Share. If you are using the storage account key, those credentials are usually stored with cmdkey: cmdkey /add:mystorageaccount.file.core.windows.net /user:localhost\mystorageaccount /pass:storage-account-key
Step 5. Specify the user in the IIS virtual directory