Search code examples
c#azurefile-storageazure-files

Azure Files Mount to Cloud Service


I followed this tutorial and everything seemed to be working fine locally, however when i hosted my web app on Azure and tried to mount/access file storage i get "Access is denied" however i am certain my credentials are correct as they work locally. Is there something extra i must add when on an azure environment (auth wise)?

I suspect it is something to do with the fact that the tutorial uses dlls that may not be available on an azure environment, if this is the issue links/hints to how i could go about resolving would be very appreciated.

worth mentioning: both Web app and file storage are in the same region on azure.

Thanks!


Solution

  • As David Makogon mentioned that Azure Files volumes can't be mounted to Azure Web App.

    Would something like this learn.microsoft.com/en-us/rest/api/storageservices/… be appropriate?

    If we want to operate the files in the Azure file storage. I recommand that you could use Azure File storage SDK to do that. We also could get demo code from Develop for Azure Files with .NET.

    CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
    
    // Get a reference to the file share we created previously.
    CloudFileShare share = fileClient.GetShareReference("logs");
    
    // Ensure that the share exists.
    if (share.Exists())
    {
        // Get a reference to the root directory for the share.
        CloudFileDirectory rootDir = share.GetRootDirectoryReference();
    
        // Get a reference to the directory we created previously.
        CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("CustomLogs");
    
        // Ensure that the directory exists.
        if (sampleDir.Exists())
        {
            // Get a reference to the file we created previously.
            CloudFile file = sampleDir.GetFileReference("Log1.txt");
    
            // Ensure that the file exists.
            if (file.Exists())
            {
                // Write the contents of the file to the console window.
                Console.WriteLine(file.DownloadTextAsync().Result);
            }
        }
    }