简体   繁体   中英

Microsoft.Azure.Storage.StorageException: The account being accessed does not support http

I'm inserting a new xml file created with in the code into our file share folder in Azure. I have Secure transfer required set to enabled but still getting "Microsoft.Azure.Storage.StorageException: The account being accessed does not support http". I'm not sure where to look. Here is my code.

            const string storageAccountName = "TestAccount";
            const string storageAccountKey = "AccountKey";
            var storageAccount =
                new CloudStorageAccount(
                    new StorageCredentials(storageAccountName, storageAccountKey), false);

            //See if FileShare folder is there
            var share = storageAccount.CreateCloudFileClient().GetShareReference("MainFolder");
            share.CreateIfNotExists();

            //Get a reference to the root of the FileShare folder
            var rootDirectory = share.GetRootDirectoryReference();
            
            //Get a reference to the next level folder
            var folder1 = rootDirectory.GetDirectoryReference("Folder1");
            folder1.CreateIfNotExists();
            
            //Get a reference to the next level folder
            var pendingFolder = rootDirectory.GetDirectoryReference("Pending");
            pendingFolder.CreateIfNotExists();

            pendingFolder.GetFileReference("tested.txt").UploadText("Testing CreateCloudFileClient");

If you review the constructor, the second parameters specifies to use https:

public CloudStorageAccount (
    Microsoft.Azure.Storage.Auth.StorageCredentials storageCredentials,
    bool useHttps);

Change this code:

   var storageAccount =
                new CloudStorageAccount(
                    new StorageCredentials(storageAccountName, storageAccountKey), false);

To:

   var storageAccount =
                new CloudStorageAccount(
                    new StorageCredentials(storageAccountName, storageAccountKey), useHttps: true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM