在 Azure 门户上,我可以设置基于路径的规则,这些规则具有一些默认设置和子规则列表 (UrlPathMap)。
每个子规则都有必须配置的名称、路径、后端池和 HTTP 设置。
正如我所看到的,我可以通过 Azure 门户轻松更新此地图。
我希望能够在应用程序安装过程中从代码动态创建此类子规则。我更喜欢直接从 .NET (ASP.NET Core 3.1) 应用程序执行此操作,但 Azure CLI 或 Azure Powershell 脚本也适合我。
此时,我尝试使用 Microsoft.Azure.Management.Fluent 库、Azure CLI 和 Azure Powershell,但我没有看到执行所需操作的直接选项。
很高兴在这里得到一些帮助。
根据我的测试,我们可以使用以下PowerShell脚本来创建子规则。
Connect-AzAccount
$groupName=""
$gatewayName=""
$poolNmae=""
$httpName=""
$pathRuleName=""
# get original sub-rule in your path rule
$appgateway=Get-AzApplicationGateway -Name $gatewayName -ResourceGroupName $groupName
$pathmap=Get-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgateway -Name $pathRuleName
$t =$pathmap.PathRules.ToArray()
# add a new sub-rule to the path rule
# 1. get the require backendpool or backendhttp settings
$pool=Get-AzApplicationGatewayBackendAddressPool -Name $poolNmae -ApplicationGateway $appgateway
$http=Get-AzApplicationGatewayBackendHttpSetting -Name $httpName -ApplicationGateway $appgateway
# 2. create the sub-rule
$r=New-AzApplicationGatewayPathRuleConfig -Name "rule01" -Paths "/path" -BackendAddressPool $pool -BackendHttpSettings $http
$t += $r
# 3. update the path rule to add the new sub rule
Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgateway -Name $pathmap.Name -PathRules $t -DefaultBackendAddressPool $pool -DefaultBackendHttpSettings $http
# 4. make the update effective
Set-AzApplicationGateway -ApplicationGateway $appgateway
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)