How to get Azure Storage Account Key (connectionString) using azure .net sdk or fluent API?

1.2k views Asked by At

I want get Azure Storage Account Key (connectionString) using azure .NET SDK or fluent API.

enter image description here

1

There are 1 answers

0
Stanley Gong On BEST ANSWER

Try this :

    var azure = Azure.Configure().Authenticate(credentials).WithSubscription(subscriptionID);

    var storageName = "<storage name>";
    var resourceGroup = "<storage resource group>";

    var keys = azure.StorageAccounts.GetByResourceGroup(resourceGroup, storageName).GetKeys();
    
    var key1 = keys[0];
    var key2 = keys[1];

    var connStr1 = "DefaultEndpointsProtocol=https;AccountName=" + storageName + ";AccountKey="+ key1.Value + ";EndpointSuffix=core.windows.net";
    var connStr2 = "DefaultEndpointsProtocol=https;AccountName=" + storageName + ";AccountKey=" + key2.Value + ";EndpointSuffix=core.windows.net";