简体   繁体   中英

Unable to get storage account key with Azure Fluent

I created a storage account with Azure Fluent SDK. But after I created the storage account, I wanted to get the name and key to build the connection string that I can use to access the storage account. The problem is that the 'Key' property is a Guid, not the key shown in the Azure Portal.

This is how I create the storage account.

IStorageAccount storage = azure.StorageAccounts.Define(storageAccountName)
    .WithRegion(Region.USEast)
    .WithNewResourceGroup(rgName)
    .Create();

How can I get the proper Key to build the connection string?

You should be able to do it via the below code, this documentation also shows the use of Fluent but only the auth methods:

    // Get a storage account
var storage = azure.StorageAccounts.GetByResourceGroup("myResourceGroup", "myStorageAccount");

// Extract the keys
var storageKeys = storage.GetKeys();

// Build the connection string
string storageConnectionString = "DefaultEndpointsProtocol=https;"
        + "AccountName=" + storage.Name
        + ";AccountKey=" + storageKeys[0].Value
        + ";EndpointSuffix=core.windows.net";

// Connect
var account = CloudStorageAccount.Parse(storageConnectionString);

// Do things with the account here...

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