如何使用.NET SDK在Azure DNS记录集中添加多个TXT记录

yqlxgs2m  于 2023-06-06  发布在  .NET
关注(0)|答案(1)|浏览(128)
var recordSetParams = new RecordSet();
                recordSetParams.TTL = 3600;
                recordSetParams.TxtRecords = new List<TxtRecord>();
                var strings = new List<string>();
                var records = new List<string>() { "record1", "record2", "record3" };
                foreach (var record in records)
                {
                    strings.Add(record);
                }

                recordSetParams.TxtRecords.Add(new TxtRecord(strings));

                await DnsClient.RecordSets.CreateOrUpdateAsync(ResourceGroupName, zone.Name, Name,RecordType.TXT, recordSetParams);

TXT record created but on same line
有没有什么方法可以将记录添加到多行上。
[Ref]:https://learn.microsoft.com/en-us/azure/dns/dns-sdk
预期结果enter image description here

h79rfbju

h79rfbju1#

我已经按照你的要求复制了。下面是我的代码。

using System;
using System.Collections.Generic;
using Azure.Identity;
using ConsoleApp8;
using Microsoft.Azure.Management.Dns.Fluent.Models;
using Microsoft.Azure.Management.Dns.Fluent;

namespace ConsoleApp9
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            string subscriptionId = "<your-subscription-id>";
            string resourceGroupName = "<your-resource-group-name>";
            string zoneName = "<your-zone-name>";
            string recordSetName = "<your-record-set-name>";

            var credential = new DefaultAzureCredential();
            var dnsClient = new DnsManagementClient(credential);

            var recordSetParams = new RecordSet();
            recordSetParams.TTL = 3600;

            var records = new List<string>() { "Recordvalue", "Recordvalue1", "Recordvalue2" };
            recordSetParams.TxtRecords = new List<TxtRecord>
        {
            new TxtRecord(records)
        };

            await dnsClient.RecordSets.CreateOrUpdateAsync(resourceGroupName, zoneName, recordSetName, RecordType.TXT, recordSetParams);

            Console.WriteLine("TXT records added successfully.");
        }
    }
}

下面是我的应用程序中的install包。

输出:

  • 以下是Azure DNS区域中的多个TXT记录。

相关问题