我创建了一个表单,可以在其中添加也可以删除自定义域和证书。 我通过以下方式删除域名:
var hostBinding = hostnameBindings.Get(_customDomain);
if (hostBinding != null)
{
SiteHostNameBindingResource siteHostNameBinding = hostBinding.Value;
await siteHostNameBinding.DeleteAsync(WaitUntil.Completed);
}
但我不知道如何删除证书:
AppCertificateCollection certcollection = _resourceGroupResource.GetAppCertificates();
如果我知道证书的名称,我可以这样做:
var certificate = certcollection.Exists("name");
certificate.Delete();
尝试下面的 C# 代码。它将获取 RG 中的所有资源并查看该资源是否是证书。如果是证书,您可以调用DeleteAsync()来删除证书。此处为 AppCertificateResource 的 MSFT 文档。 https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.appservice.appcertificateresource?view=azure-dotnet
using System;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.Core;
using Azure.Security.KeyVault.Certificates;
using Azure.ResourceManager.AppService;
public class AzureResourceGroupExample
{
public static async Task Main(string[] args)
{
string subscriptionId = "xxxx";
string resourceGroupName = "rg-xxx";
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
ResourceIdentifier subscriptionResourceId = new ResourceIdentifier($"/subscriptions/{subscriptionId}");
SubscriptionResource subscription = armClient.GetSubscriptionResource(subscriptionResourceId);
ResourceGroupResource _resourceGroupResource = await subscription.GetResourceGroupAsync(resourceGroupName);
Console.WriteLine($"Resource group retrieved: {_resourceGroupResource.Data.Name}");
await foreach (var resource in _resourceGroupResource.GetGenericResourcesAsync())
{
if (resource.Data.ResourceType == "Microsoft.Web/certificates")
{
var certificateResource = await _resourceGroupResource.GetAppCertificateAsync(resource.Data.Name);
Console.WriteLine($"- Certificate Resource: {certificateResource.Value.Id}");
// certificateResource.Value.DeleteAsync();
}
else
{
Console.WriteLine($"- Resource: {resource.Data.Name}, Type: {resource.Data.ResourceType}");
}
}
}
}