Add a custom domain to your CDN endpoint using .NET SDK

Anuraj 166 Reputation points MVP
2021-01-04T12:32:47.883+00:00

I am using Azure CDN / Blob for my Angular application. I would like to enable custom domain support - so that my end users can map the application domain themself. I thought of using Azure SDK. So far I did like this.

var cndCNAME = "dotnetthoughts";

var clientId = _configuration["ClientId"];
var clientSecret = _configuration["ClientSecret"];
var tenantId = _configuration["TenantId"];
var credentials = SdkContext.AzureCredentialsFactory
    .FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
var azure = Microsoft.Azure.Management.Fluent.Azure
    .Configure()
    .Authenticate(credentials)
    .WithDefaultSubscription();

var cndProfile = azure.CdnProfiles.GetById("/subscriptions/<SUBSCRIPTIONID>/resourceGroups/anuraj/providers/microsoft.cdn/profiles/anuraj-dev-cdn");
var customDomainValidationResult = cndProfile.ValidateEndpointCustomDomain(cndCNAME, "demo.anuraj.dev");
if (customDomainValidationResult.CustomDomainValidated)
{
    cndProfile.Update()
        .DefineNewEndpoint()
        .WithOrigin("https://anuraj.z29.web.core.windows.net")
        .WithCustomDomain("demo.anuraj.dev")
        .Attach()
        .Apply();
}

Till the verification it is working. But when I try update the domain, it is failing - Bad Request Error.

Please help.

Azure Content Delivery Network
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SaiKishor-MSFT 17,216 Reputation points
    2021-01-06T19:13:20.087+00:00

    @Anuraj

    Have you followed this document for adding a custom domain to your endpoint? I did a Nslookup for the domain- demo.anuraj.dev and that did not return anything.