azure - 无法使用 Azure Fluent 获取存储帐户密钥
问题描述
我使用 Azure Fluent SDK 创建了一个存储帐户。但在创建存储帐户后,我想获取名称和密钥来构建可用于访问存储帐户的连接字符串。问题是“密钥”属性是一个 Guid,而不是 Azure 门户中显示的密钥。
这就是我创建存储帐户的方式。
IStorageAccount storage = azure.StorageAccounts.Define(storageAccountName)
.WithRegion(Region.USEast)
.WithNewResourceGroup(rgName)
.Create();
如何获得正确的密钥来构建连接字符串?
解决方案
您应该可以通过下面的代码来做到这一点,该文档还显示了 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...
推荐阅读
- firebase-realtime-database - Firebase 数据库“强”规则
- automation - 在空手道和放心之间进行选择
- 3d - 在 gnuplot 中使用 xy 文件绘制圆柱坐标
- php - Jquery Post数据未定义
- javascript - Method Not Allowed 请求的 URL POST 请求不允许该方法
- python - 使用递归或其他方法获取数字总和(整数分区)的方法数
- php - 更新 Laravel 关系中的对象
- google-apps-script - 从 Google Apps 脚本将 mp3 文件上传到 Google Drive
- go - 为什么 Go 中的错误可以为零?
- blazor - 从 Server Blazor 客户端加载图像