azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

What is the SDK equivalent of Set-AzWebApp?

Open josephsctan opened this issue 2 years ago • 1 comments

Library name and version

Azure.ResourceManager.AppService 1.0.0-beta-3

Query/Question

Hi there,

I'am trying to attach a custom domain name to a App Service.

In Powershell, this is how I would do it:

Set-AzWebApp -Name customdnsdev -ResourceGroupName TESTRESOURCE -HostNames @('site1.contoso.com','customdnsdev.azurewebsites.net')

How do I do this using Azure.ResourceManager.AppService?

Environment

No response

josephsctan avatar Aug 08 '22 09:08 josephsctan

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Aug 08 '22 12:08 jsquire

hi @josephsctan, you can achieve the custom binding by the following code

  public void UpdateWebSiteCustomDomain(string resourceGroupName)
        {
           //this.client is an ArmClient
            var resourceGroup = this.client.GetDefaultSubscription().GetResourceGroup(resourceGroupName).Value;
            var website = resourceGroup.GetWebSite("your website name").Value;
            HostNameBindingData data = new HostNameBindingData()
            {
                
            };
            var binding=website.GetSiteHostNameBindings().CreateOrUpdate(Azure.WaitUntil.Completed, "your domain", data).Value;

        }

Is this domain you purchased from external or from azure app service domain? I'm asking this because to bind a domain purchase from outside requires azure to detect if you are the owner of the domain by update some DNS record in domain provider portal, this is not something azure sdk can do

xboxeer avatar Aug 18 '22 07:08 xboxeer

Thanks. The domain is external.

On Thu, Aug 18, 2022 at 7:06 PM Elendil @.***> wrote:

hi @josephsctan https://github.com/josephsctan, you can achieve the custom binding by the following code

public void UpdateWebSiteCustomDomain(string resourceGroupName) { var resourceGroup = this.client.GetDefaultSubscription().GetResourceGroup(resourceGroupName).Value; var website = resourceGroup.GetWebSite("your website name").Value; HostNameBindingData data = new HostNameBindingData() {

        };
        var binding=website.GetSiteHostNameBindings().CreateOrUpdate(Azure.WaitUntil.Completed, "your domain", data).Value;

    }

Is this domain you purchased from external or from azure app service domain?

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-net/issues/30386#issuecomment-1219113963, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOO6Z2KY5WVSO64FRYZ7S3VZXOGBANCNFSM554M2KGA . You are receiving this because you were mentioned.Message ID: @.***>

josephsctan avatar Aug 18 '22 08:08 josephsctan

@josephsctan is there any other issue you have with the sample code? If no, feel free to let us know your overall feelings about our SDK in this Survey, thanks!

xboxeer avatar Aug 22 '22 05:08 xboxeer

All good thanks.

The SDK pattern [ GetXXXX().CreateOrUpdate() ] certainly takes some getting used to!

josephsctan avatar Aug 24 '22 03:08 josephsctan