Unable to delete custom domain from static web app

WRex 0 Reputation points
2025-02-14T19:16:59.2433333+00:00

I recently attempted to delete a custom domain from an Azure static web app. It has been stuck in the deleting status for several weeks. I've attempted to delete it from the GUI multiple times over the course of the past few weeks.

All DNS records for the custom domain (CNAME, etc) are still active.

I've also attempted to run the following PowerShell command (with the correct names for each variable):

$rg = "[resource group name]";
$name = "[static web app name]";  
$remove_me = "[custom domain name]";  
$domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;
$len = $domains.Length;  
while($len -eq $domains.Length){  
        foreach($item in $domains){  
            if($item.name -eq $remove_me){  
                $err = Remove-AzStaticWebAppCustomDomain -DomainName $remove_me -Name $name -ResourceGroupName $rg -NoWait;  
                $domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;   
                if($domains.Length -gt 0){  
                    Write-Host "$remove_me still exists. Retrying...";  
                    Start-Sleep -s 10;  
                }  
            }  
        }   
    }  
Write-Host "Success!";

As well as this by itself:

Remove-AzStaticWebAppCustomDomain -ResourceGroupName [resource group] -Name [static web app] -DomainName [custom domain name]

Neither has worked, with the logs showing:

User's image

As well as this in PowerShell:

Remove-AzStaticWebAppCustomDomain_Delete: The server responded with an unrecognized response, Status: OK

Any assistance would be appreciated in resolving this.

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,087 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 3,145 Reputation points Microsoft Vendor
    2025-02-25T20:15:25.3966667+00:00

    Hi @Wrex ,
    Thanks for reaching out to Microsoft Q&A.
    As your description, your custom domain is stuck in the deleting state for several weeks. Even after multiple retries using the Azure portal and PowerShell commands, it remains undeleted.
    Remove DNS Records Before Deleting Before attempting another delete operation, ensure that all DNS records (CNAME, TXT) associated with the domain are removed from your domain registrar.

    Use Azure CLI to Force Delete Try deleting the custom domain using Azure CLI, as it may bypass UI-related issues,
    az staticwebapp hostname delete -n "<static-webapp-name>" -g "<resource-group>" --hostname "<custom-domain>"
    Use PowerShell Script (Retry Delete Until Success) If the CLI fails, use a PowerShell loop to keep retrying the deletion until it succeeds.

    $name = "<static-webapp>";  
    $remove_me = "sub.domain.com";  
    $domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;  
    $len = $domains.Length;  
    while($len -eq $domains.Length){  
            foreach($item in $domains){  
                if($item.name -eq $remove_me){  
                    $err = Remove-AzStaticWebAppCustomDomain -DomainName $remove_me -Name $name -ResourceGroupName $rg -NoWait;  
                    $domains = Get-AzStaticWebAppCustomDomain -ResourceGroupName $rg -Name $name;   
                    if($domains.Length -gt 0){  
                        Write-Host "$remove_me still exists. Retrying...";  
                        Start-Sleep -s 10;  
                    }  
                }  
            }   
        }  
    Write-Host "Success!";
    

    Give Deleting a Shot via Azure Resource Explorer

    Open it up

    Head to: subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Web/staticSites/{static-web-app-name}/customDomains/{domain-name}

    Try deleting the domain manually.

    Look for Azure Resource Locks If your Static Web App or resource group has a delete lock, remove it by going to: Azure Portal > Resource Group > Settings > Locks
    ref:

    https://learn.microsoft.com/en-us/answers/questions/923400/unable-to-delete-custom-domain-from-static-web-app
    Let me know if you have any further assistances.
    If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.


  2. WRex 0 Reputation points
    2025-02-27T14:33:18.32+00:00

    I've attempted to delete it from the Azure Resource Manager as well as manually, but it did not work.

    The resource group currently has no locks in place.

    When using the command you provided (with correct information):

    az staticwebapp hostname delete -n "<static-webapp-name>" -g "<resource-group>" --hostname "<custom-domain>"
    

    I get the following output and the custom domain isn't deleted:

    Are you sure you want to perform this operation? (y/n): y
    After deleting a custom domain, there can be a 15 minute delay for the change to propagate.
    (Unspecified) 
    Code: Unspecified
    Message: 
    

    The script I ran originally came from the forum post you linked.

    I am in the process of removing the DNS entries.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.