我想通过Powershell为WebApp设置Cors allowedOrigins选项,但无法使其正常工作。
有人可以帮忙完成这项工作吗?
以下是我的脚本无效
$Resource = Get-AzureRmResource -ResourceType Microsoft.Web/sites/config -ResourceGroupName "####" -ResourceName "####" -ApiVersion 2015-08-01
$Resource.Properties.cors = @{allowedOrigins = "*"}
$Resource.Properties.cors.allowedOrigins = "*"
$Resource | Set-AzureRmResource -ApiVersion 2015-08-01 -Force
答案 0 :(得分:2)
博客here中提供的脚本可用于此目的:
$webAppName = "powershelldemowebapp"
$subscriptionId = "xxxx-xxxx-xxx-xxxx-xxxx-xxxx-xxx"
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId $subscriptionId
$rgName = GetResourceGroupForWebApp $webAppName
$allowedOrigins = @()
$allowedOrigins += "*"
$allowedOrigins += "www.yourdomain.com"
$PropertiesObject = @{cors = @{allowedOrigins= $allowedOrigins}}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $rgName -ResourceType Microsoft.Web/sites/config -ResourceName $webAppName/web -ApiVersion 2015-08-01 -Force
答案 1 :(得分:0)
我找到了解决方案
修复
$Resource.Properties.cors = @{allowedOrigins = @("http://example.net")}