无法使用Azure Fluent获取存储帐户密钥
我用Azure Fluent SDK创建了一个存储帐户。但是在我创建了存储帐户之后,我想获得名称和密钥来构建连接字符串,我可以使用该字符串访问存储帐户。问题在于“Key”属性是Guid,而不是Azure门户中显示的密钥 这就是我创建存储帐户的方式无法使用Azure Fluent获取存储帐户密钥,azure,azure-storage,azure-fluent-api,Azure,Azure Storage,Azure Fluent Api,我用Azure Fluent SDK创建了一个存储帐户。但是在我创建了存储帐户之后,我想获得名称和密钥来构建连接字符串,我可以使用该字符串访问存储帐户。问题在于“Key”属性是Guid,而不是Azure门户中显示的密钥 这就是我创建存储帐户的方式 IStorageAccount storage = azure.StorageAccounts.Define(storageAccountName) .WithRegion(Region.USEast) .WithNewResource
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...
下面的回答对你有帮助吗Keisha?这对我很有用谢谢。我想我以前已经接受了答案。非常感谢。帮助我