简体   繁体   English

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

[英]How to Add Tags to Azure Resource from a C# - Web Application

How can I add Tags to an azure resource using C# Code in my ASP.NET Application. 如何在ASP.NET应用程序中使用C#代码将标签添加到蔚蓝资源中。 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. 如果有人知道如何将标签附加到资源,请提供帮助。

Note: (i)I have tried the Azure ServiceManagement API but I see there is no API support for attaching a tag to a resource. 注意:(i)我已经尝试过Azure ServiceManagement API,但是我看不到将标签附加到资源的API支持。 (ii) Will powershell Cmdlets a viable option if nothing else works? (ii)如果没有其他方法,powershell Cmdlet是否将是可行的选择?

Follow this link to create client application in AD and service principle. 单击此链接以AD和服务原理创建客户端应用程序。 Make note of tenantId, ClientId and ClientKey 记下tenantId,ClientId和ClientKey

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

Find the resource, add / update tags and patch it. 查找资源,添加/更新标签并打补丁。

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

PowerShell could easily do this, you can use the command below: PowerShell可以轻松地做到这一点,您可以使用以下命令:

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

Check this article for details. 查看本文以了解详细信息。

If anyone interested in a way to try out through REST API, I found this after spying on powershell bound traffic using Fiddler. 如果有人对尝试通过REST API进行尝试感兴趣,那么在使用Fiddler监视Powershell绑定流量后,我就发现了这一点。 Note the tag as json-payload. 注意标记为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"
  }
}**

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在C#中向资源文件添加控件以本地化Winform应用程序 - How to add a control to a resource file in C# for localizing a winform application 如何将存储在 web.config 中的值添加到 c# 中的类属性(来自 web 配置文件而不是资源文件) - How can I add a value that is stored in web.config to a class attribute in c#(from web config file not the resource file) 我可以从本地 C# 应用程序列出 Azure 资源组吗? - Can I list Azure resource groups from a local C# application? 无法从C#MVC应用程序请求Azure资源管理器 - Can't request Azure Resource Manager from c# MVC application 如何将Web Interface添加到C#Windows应用程序 - How to add Web Interface to C# Windows Application 如何在Visual Studio 2010中向C#Web应用程序添加计时器 - How to add a timer to c# Web Application in Visual studio 2010 如何在C#Web表单应用程序的内容页面中添加脚本 - How to add script in content page of c# web form application 如何使用Azure SDK在c#.net core中创建“ Web App bot”类型的资源 - How to use Azure SDK to Create resource of Type “Web App bot” in c# .net core 从一台计算机而不是另一台计算机部署时,C#Web应用程序在Azure中导致404错误 - C# web application causes 404 error in Azure when deployed from one computer, but not from another 如何在C#中的Web应用程序中从服务器加载图像 - How to load an image from the server in a web application in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM