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

查看:20
本文介绍了如何从 .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 门户轻松更新此地图.作为应用程序安装的一部分,我希望能够从代码动态创建此类子规则.我更愿意直接从 .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天全站免登陆