Dela via


Microsoft Azure Dns management client library for .NET

Microsoft Azure Dns is a hosting service for Dns domains that provides name resolution by using Microsoft Azure infrastructure. By hosting your domains in Microsoft Azure, you can manage your Dns records by using the same credentials, APIs, tools, and billing as your other Azure services.

This library supports managing Microsoft Azure Dns resources.

This library follows the new Azure SDK guidelines, and provides many core capabilities:

- Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET.
- Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
- HTTP pipeline with custom policies.
- Better error-handling.
- Support uniform telemetry across all languages.

Getting started

Install the package

Install the Azure DNS management library for .NET with NuGet:

dotnet add package Azure.ResourceManager.Dns

Prerequisites

Authenticate the Client

To create an authenticated client and start interacting with Microsoft Azure resources, see the quickstart guide here.

Key concepts

Key concepts of the Microsoft Azure SDK for .NET can be found here.

Documentation

Documentation is available to help you learn how to use this package:

Examples

Create a Dns zone

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the DnsZone collection from the resource group
DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones();
// Use the same location as the resource group
string dnsZoneName = "sample.com";
DnsZoneData data = new DnsZoneData("Global")
{
};
ArmOperation<DnsZoneResource> lro = await dnsZoneCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsZoneName, data);
DnsZoneResource dnsZone = lro.Value;

Get all Dns zones in a resource group

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the DnsZone collection from the resource group
DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones();
// With ListAsync(), we can get a list of the DnsZones
AsyncPageable<DnsZoneResource> response = dnsZoneCollection.GetAllAsync();
await foreach (DnsZoneResource dnsZone in response)
{
    Console.WriteLine(dnsZone.Data.Name);
}

Delete a Dns zone

ArmClient armClient = new ArmClient(new DefaultAzureCredential());
SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
// Now we get the DnsZone collection from the resource group
DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones();
string dnsZoneName = "sample.com";
DnsZoneResource dnsZone = await dnsZoneCollection.GetAsync(dnsZoneName);
await dnsZone.DeleteAsync(WaitUntil.Completed);

Troubleshooting

Next steps

More sample code

Other Documentation

For more information about Microsoft Azure SDK, see this website.

Contributing

For details on contributing to this repository, see the contributing guide.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (for example, label, comment). Follow the instructions provided by the bot. You'll only need to do this action once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any other questions or comments.