如何从C#Web应用程序向Azure资源添加标记

如何从C#Web应用程序向Azure资源添加标记,c#,azure,tags,C#,Azure,Tags,如何在ASP.NET应用程序中使用C#代码向azure资源添加标记。 我正在尝试创建azure标记管理门户 我发现了这个,但它是关于向资源组添加标记的。此外,该库似乎已被弃用。如果有人知道如何将标签附加到资源,请提供帮助 注意:(i)我已经尝试了,但是我发现没有API支持将标记附加到资源。(ii)如果其他方法都不起作用,powershell cmdlet是否是可行的选项?powershell可以轻松做到这一点,您可以使用以下命令: PS C:\> Set-AzureRmResource -

如何在ASP.NET应用程序中使用C#代码向azure资源添加标记。 我正在尝试创建azure标记管理门户

我发现了这个,但它是关于向资源组添加标记的。此外,该库似乎已被弃用。如果有人知道如何将标签附加到资源,请提供帮助


注意:(i)我已经尝试了,但是我发现没有API支持将标记附加到资源。(ii)如果其他方法都不起作用,powershell cmdlet是否是可行的选项?

powershell可以轻松做到这一点,您可以使用以下命令:

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

查看详细信息。

PowerShell可以轻松完成此操作,您可以使用以下命令:

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

查看详细信息。

如果有人对通过REST API进行尝试感兴趣, 我是在使用Fiddler监视powershell的流量后发现的。请注意标记为json负载

{subscription id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/virtualMachines/{VM name}

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"
  }
}**
补丁**https://management.azure.com/subscriptions/6dcd{subscribd}e8f/resourceGroups/css dev/providers/Microsoft.Sql/servers/css development/databases/css dev?api version=2014-04-01 HTTP/1.1**
授权:持有人sDSEsiJKV1QiLCJhbG[]XDVZBJG5JH0RIVEHVDS
用户代理:AzurePowershell/v1.0.0.0
ParameterSetName:驻留在订阅级别的资源。
CommandName:Set AzureRmResource
内容类型:application/json;字符集=utf-8
主持人:management.azure.com
内容长度:52
预期:100人继续
连接:保持活力
**{
“标签”:{
“displayName”:“AzureV1”
}
}**

如果有人对通过REST API进行尝试感兴趣, 我是在使用Fiddler监视powershell的流量后发现的。请注意标记为json负载

{subscription id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/virtualMachines/{VM name}

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"
  }
}**
补丁**https://management.azure.com/subscriptions/6dcd{subscribd}e8f/resourceGroups/css dev/providers/Microsoft.Sql/servers/css development/databases/css dev?api version=2014-04-01 HTTP/1.1**
授权:持有人sDSEsiJKV1QiLCJhbG[]XDVZBJG5JH0RIVEHVDS
用户代理:AzurePowershell/v1.0.0.0
ParameterSetName:驻留在订阅级别的资源。
CommandName:Set AzureRmResource
内容类型:application/json;字符集=utf-8
主持人:management.azure.com
内容长度:52
预期:100人继续
连接:保持活力
**{
“标签”:{
“displayName”:“AzureV1”
}
}**

遵循此链接以AD和服务原则创建客户端应用程序。记下tenantId、ClientId和ClientKey

查找资源,添加/更新标记并对其进行修补

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);

按照此链接以AD和服务原则创建客户端应用程序。记下tenantId、ClientId和ClientKey

查找资源,添加/更新标记并对其进行修补

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);

谢谢,这很有帮助。azure powershell脚本执行表单c#代码将是我现在需要探索的东西。:)谢谢,这很有帮助。azure powershell脚本执行表单c#代码将是我现在需要探索的东西。:)