【问题标题】:Unable to get storage account key with Azure Fluent无法使用 Azure Fluent 获取存储帐户密钥
【发布时间】:2019-01-14 20:10:13
【问题描述】:

我使用 Azure Fluent SDK 创建了一个存储帐户。但在创建存储帐户后,我想获取名称和密钥来构建可用于访问存储帐户的连接字符串。问题是“密钥”属性是一个 Guid,而不是 Azure 门户中显示的密钥。

这就是我创建存储帐户的方式。

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

如何获得正确的密钥来构建连接字符串?

【问题讨论】:

  • 下面的回复对你有帮助吗?
  • 这对我有用,谢谢。我以为我之前接受了答案。

标签: azure azure-storage azure-fluent-api


【解决方案1】:

你应该可以通过下面的代码来做到这一点,这个documentation 也显示了 Fluent 的使用,但只有 auth 方法:

    // 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...

【讨论】:

  • 非常感谢。帮助了我
猜你喜欢
  • 1970-01-01
  • 2018-10-09
  • 2017-05-01
  • 2018-01-08
  • 2021-05-18
  • 2020-11-05
  • 1970-01-01
  • 2018-04-28
  • 2017-08-19
相关资源
最近更新 更多