How to update Azure Application Gateway Path Based Rule UrlPathMap from .NET

巧了我就是萌 提交于 2021-01-28 07:19:27

问题


On Azure Portal, I am able to setup path-based rules which have some default setting, and a list of sub-rules (UrlPathMap).

Each of those sub-rules has a name, paths, backend pool, and HTTP setting that have to be configured.

As I can see I can update this map easily through Azure Portal. I want to be able to create such sub-rules dynamically from code as part of the application installation. I would prefer to do this directly from .NET (ASP.NET Core 3.1) application, but Azure CLI or Azure Powershell script should be OK for me as well.

At this point, I tried to use Microsoft.Azure.Management.Fluent library, Azure CLI and Azure Powershell but I do not see the direct option to do what is need.

Will be really glad to get some help here.


回答1:


According to my test, we can use the following PowerShell script to create a sub-rule.

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



来源:https://stackoverflow.com/questions/59756000/how-to-update-azure-application-gateway-path-based-rule-urlpathmap-from-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!