Microsoft.Azure.Storage.StorageException: 被访问的账号不支持http

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

我将在代码中创建的新 xml 文件插入到 Azure 中的文件共享文件夹中。我已将“需要安全传输”设置为启用,但仍然收到“Microsoft.Azure.Storage.StorageException:正在访问的帐户不支持 http”。我不确定在哪里看。这是我的代码。

            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");

如果查看constructor,第二个参数指定使用https:

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

更改此代码:

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

收件人:

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