[英]Unable to get storage account key with 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...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.