4

I've got an ASP.NET application that needs to read and write from an Azure Fileshare. I cannot set permissions directly on the Azure Fileshare, rather, I have the storage account key and primary access key.

I can get on my server and use the "net use" command to mount the fileshare as a drive. Because of the answer to a previous question, I know that ASP.NET will not be able to see the mounted drive.

I was able to get this to work from my local machine, running IIS under my local user and adding the azure storage account file share to the credential manager, but this does not work on the server, so I'm missing some piece of the puzzle.

On the server, if I try to access the share using

Directory.Exists(@"\\storageaccountkey.file.core.windows.net\sharename");

this does not work from ASP.NET (I suspect this is because ASP.NET is unable to authenticate to the share). Running this code from LINQpad does work and returns true.

I have tried adding the credentials to the credential manager and running my application pool under the user who I'm running the credential manager under, but I still get a 'false' returned from the Directory.Exists().

Why can I not see the directory on the server?

Community
  • 1
  • 1
tarun713
  • 2,177
  • 3
  • 17
  • 31

1 Answers1

2

I'd like to suggest you use Storage Client Library to access a file share, check the official article https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-files/

You can use the code below instead of Directory.Exists to access the share:

    // Parse the connection string for the storage account.
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));

    // Create a CloudFileClient object for credentialed access to File storage.
    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())
    {
        //do something    
    }
forester123
  • 1,549
  • 10
  • 10
  • Thanks. My trouble is - the application isn't mine. It's from a vendor of ours who is not set up to read using Azure libraries, so if possible, I'd really like to figure out how to get this working as an SMB share rather than asking the vendor to implement Azure specific code. – tarun713 Mar 03 '16 at 14:29
  • tarun, did u find the solution? – kudlatiger Apr 20 '16 at 05:31
  • note: if you're needing this to work locally for your devs then the SCL is a better solution as ISPs very frequently block the ports required for SMB shares. I was unable to access them using ATT UVerse or a GoDaddy dedicated server. Switching to this library certainly isn't as easy as just using a \\ pathname but has additional benefits such as this. – Simon_Weaver Apr 26 '17 at 21:12