簡體   English   中英

如何獲取Azure ResourceManagementClient對象的標記

[英]How to get Tags of Azure ResourceManagementClient object

我正在嘗試使用ResourceManagementClient類獲取資源組的標記列表。

軟件包管理器控制台添加“Microsoft.Azure.Management.Resources 2.14.1-preview”

ResourceManagementClient resourceClient = new ResourceManagementClient(new Microsoft.Azure.CertificateCloudCredentials(SubscriptionId, cert));

var tags = resourceClient.Tags.List();

我收到這個錯誤; AuthenticationFailed:身份驗證失敗。 “授權”標題不存在或以無效格式提供。

在另一個樣本中,該部分正在下面工作;

StorageManagementClient storageClient = new StorageManagementClient(new Microsoft.WindowsAzure.CertificateCloudCredentials(SubscriptionId, cert));

這些代碼部分之間存在差異。 Microsoft.Azure用於第一個示例, Microsoft.WindowsAzure用於第二個,第二個示例正在使用。

如何在第一個樣本中解決問題,您能解釋一下這個問題嗎?

我堅信ResourceManagementClient不能與CertificateCloudCredentials一起使用,至少對於ARM Rest API來說是這樣。 我猜您需要首先使用此處所述的登錄/密碼授權用戶,然后將獲取的令牌與ResourceManagementClient一起使用

更新:第一個鏈接描述了如何在AD中注冊應用程序,可以從門戶網站完成。 接下來,您需要在AD中注冊將成為訂閱的共同管理員的用戶。 之后使用第二個鏈接的代碼獲取授權令牌(使用在prev步驟中創建的登錄/密碼)最后使用該令牌進行ResourceManagementClient授權,類似這樣(不編譯):

var credentials = new TokenCloudCredentials(<subscrtiption id>, <token>);
new ResourceManagerClient(credentials).DoSomething();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM