Jumbo
Jumbo

Reputation: 35

Az Command powershell for adding urls in CORS of azure app service

I am in search of az commands (powershell) to add urls in azure app service while deploying

You can refer the attached image for clarity . enter image description here

Thanks in advance

Upvotes: 0

Views: 861

Answers (2)

sam256
sam256

Reputation: 1421

2023 Update

If you are coming to this answer now, it looks like the settings are now under siteConfig not config. Here's a Powershell snippet that will set some cors values and set cors to support credential passing:

    $ResourceGroupName = 'my-resource-group'
    $AppName = 'myWebServiceApp'
    $AllowedCorsHosts = @("https://somedomain.com","https://some.otherdomain.com")

    $AzResourceParams = @{
        ResourceGroupName = $ResourceGroupName
        ResourceName = $AppName
        ResourceType =  "Microsoft.Web/sites"
    }

    $WebAppResource = Get-AzResource @AzResourceParams

    $WebAppResource.Properties.siteConfig.cors = @{
        allowedOrigins = $AllowedCorsHosts 
        supportCredentials = $true
    }

    $WebAppResource | Set-AzResource -Force

Upvotes: 1

Allen Wu
Allen Wu

Reputation: 16448

Please use Set-AzResource.

An example for your reference.

$webAppName = ""
$subscriptionId = ""
$tenantId = ""
$resourceGroup = ""

Connect-AzAccount -Tenant $tenantId
Select-AzSubscription -SubscriptionId $subscriptionId

$allowedOrigins = @()
$allowedOrigins += "www.example.com"

$PropertiesObject = @{cors = @{allowedOrigins= $allowedOrigins}}

Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/config -ResourceName $webAppName/web -ApiVersion 2015-08-01 -Force

Upvotes: 1

Related Questions