2016-03-29 12 views
0

ASP.NETアプリケーションでC#コードを使用して空白リソースにタグを追加する方法を教えてください。 蒼穹タグ管理ポータルを作成しようとしています。C# - WebアプリケーションからAzureリソースにタグを追加する方法

これは、questionですが、リソースグループにタグを追加することです。また、そのライブラリは非難されているようです。リソースにタグを付ける方法を知っている人がいれば、助けてください。

注:(i)私はAzure ServiceManagement APIを試しましたが、リソースにタグを付けるためのAPIサポートはありません。 (ii)PowerShellは何も動作しない場合でも実行可能なオプションですか?詳細については、

PS C:\> Set-AzureRmResource -Tag @(@{ Name="tag_name"; Value="tag_value" }) -ResourceId <resource_id> 

チェックthis article:PowerShellは簡単にこれを行うことができます

答えて

1

REST APIを試す方法に興味がある人なら、 Fiddlerを使用してpowershellにバインドされたトラフィックを監視した結果、これが見つかりました。タグはjson-payloadとしてください。

https://management.azure.com/subscriptions/ {サブスクリプションID}/resourceGroups/{リソースグループ名} {/providers/Microsoft.Compute/virtualMachines/ VM-名}

PATCH **https://management.azure.com/subscriptions/6dcd{subscrID}e8f/resourceGroups/css-dev/providers/Microsoft.Sql/servers/css-development/databases/css-dev?api-version=2014-04-01 HTTP/1.1** 
Authorization: Bearer sDSEsiJKV1QiLCJhbG[<PARTIALLY REMOVED BY KIRAN FOR SECURITY REASON>]XDvZBJG5Jhh0rivehvDS 
User-Agent: AzurePowershell/v1.0.0.0 
ParameterSetName: Resource that resides at the subscription level. 
CommandName: Set-AzureRmResource 
Content-Type: application/json; charset=utf-8 
Host: management.azure.com 
Content-Length: 52 
Expect: 100-continue 
Connection: Keep-Alive 

**{ 
    "tags": { 
    "displayName": "AzureV1" 
    } 
}** 
1

は、あなたは以下のコマンドを使用することができます。

+0

ありがとうございます。 azure powershellスクリプトの実行フォームC#コードは私が今探る必要があるものです。 :) – WinW

1

クライアントアプリケーションを作成するには、このリンクをクリックしてくださいADとサービスの原則。 tenantId、ClientIdのとClientKeyのノート

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal

は、リソースを検索/更新タグを追加し、それにパッチを適用してください。

var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientKey); 
var resourceClient = new ResourceManagementClient(serviceCreds); 
resourceClient.SubscriptionId = subscriptionId; 

GenericResource genericResource = resourceClient.Resources.Get("some-resource-group", "Microsoft.DocumentDB", "", "databaseAccounts", "some-resource", "2016-03-31"); 

genericResource.Tags.Add("Version", "1.0"); 

resourceClient.Resources.CreateOrUpdate("some-resource-group", "Microsoft.DocumentDB", "", "databaseAccounts", "some-resource", "2016-03-31", genericResource); 
関連する問題