如何从.NET更新Azure应用程序网关基于路径的规则UrlPathMap [英] How to update Azure Application Gateway Path Based Rule UrlPathMap from .NET

查看:54
本文介绍了如何从.NET更新Azure应用程序网关基于路径的规则UrlPathMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure门户上,我能够设置基于路径的规则,这些规则具有一些默认设置以及子规则列表(UrlPathMap).

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

每个子规则都有必须配置的名称,路径,后端池和HTTP设置.

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

如我所见,我可以通过Azure Portal轻松更新此地图.我希望能够在应用程序安装过程中通过代码动态创建此类子规则.我希望直接从.NET(ASP.NET Core 3.1)应用程序执行此操作,但是Azure CLI或Azure Powershell脚本对我来说也应该可以.

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.

在这一点上,我尝试使用Microsoft.Azure.Management.Fluent库,Azure CLI和Azure Powershell,但是我看不到直接选项来执行所需的操作.

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.

推荐答案

根据我的测试,我们可以使用以下PowerShell脚本创建子规则.

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

这篇关于如何从.NET更新Azure应用程序网关基于路径的规则UrlPathMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆