azure - 无法使用 Azure Fluent 获取存储帐户 key

标签 azure azure-storage azure-fluent-api

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

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

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

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

最佳答案

您应该可以通过下面的代码来完成此操作,即 documentation还显示了 Fluent 的使用,但仅显示了身份验证方法:

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

关于azure - 无法使用 Azure Fluent 获取存储帐户 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51731805/

相关文章:

azure - 如何使用 .Net Fluent SDK 设置 Azure 容器实例托管服务身份参数

azure - 无法使用 C# 和 F# 将 aspnet 部署到 azure - 构建中的所有构建提交都必须使用源自同一项目集合的项目实例

sql-server - 打开与多个数据库的连接 - 唤醒

azure - 列出 Blob 内的文件?

c# - Azure Blob 租赁和发布

c# - 使用内置的 Exists 方法检查 Azure Blob 存储中是否存在容器和 blob

python - Azure DevOps AzureFunctionApp@1 未安装 python 依赖项

android - Twilio SMS 正文不会连接 Azure 逻辑应用程序中的 URL 参数

azure - 如何使用 Azure .NET Fluent SDK 获取 Azure 应用服务 TLS 配置信息?

c# - Azure 面向公众的负载均衡器