如何从 C# 向 Azure 资源添加标签 - Web 应用程序 [英] How to Add Tags to Azure Resource from a C# - Web Application
问题描述
如何在我的 ASP.NET 应用程序中使用 C# 代码向 azure 资源添加标签.我正在尝试创建一个 azure 标签管理门户.
How can I add Tags to an azure resource using C# Code in my ASP.NET Application. I am trying to create an azure tag management portal.
我发现了这个问题,但它是关于添加标签的到一个资源组.此外,图书馆似乎已被弃用.如果有人知道如何将标签附加到资源,请帮忙.
I found this question but it is about adding a tag to a resource group . Also that Library seems deprecated. If any one knows how to attach a tag to a Resource, Please help.
注意:(i)我已经尝试了 Azure ServiceManagement API 但我发现没有 API 支持将标签附加到资源.(ii) 如果其他方法无效,powershell Cmdlets 是否是一个可行的选择?
Note: (i)I have tried the Azure ServiceManagement API but I see there is no API support for attaching a tag to a resource. (ii) Will powershell Cmdlets a viable option if nothing else works?
推荐答案
如果有人有兴趣尝试通过 REST API 的方式,我在使用 Fiddler 监视 powershell 绑定流量后发现了这一点.请注意标记为 json-payload.
If anyone interested in a way to try out through REST API, I found this after spying on powershell bound traffic using Fiddler. Note the tag as json-payload.
https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{VM-Name}
https://management.azure.com/subscriptions/{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"
}
}**
这篇关于如何从 C# 向 Azure 资源添加标签 - Web 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!