I want get Azure Storage Account Key (connectionString)
using azure .NET SDK
or fluent API.
Asked
Active
Viewed 1,042 times
1

Alireza Ahmadi
- 8,579
- 5
- 15
- 42

DnyaneshSurya
- 187
- 1
- 1
- 14
-
Could you please tell me what you try? – Jim Xu Jun 04 '21 at 00:59
-
1Stanley's answer is correct, please accept his answer to end this question. You just need to create an aad app to get the credential before using his code. You need [these packages](https://i.stack.imgur.com/y8yTr.png). – Cindy Pau Jun 04 '21 at 02:18
1 Answers
3
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";

Stanley Gong
- 11,522
- 1
- 8
- 16