修改应用网关UrlPathMap的PathRules

Modifying PathRules of a UrlPathMap of an application gateway

我需要通过适用于 .NET 的 Azure SDK 从代码中动态添加和删除 URL 路径映射的 PathRules 目前我使用以下 nuget 包 Microsoft.Azure.Management.Fluent。 我看不出有什么方法可以做到这一点。我只能通过 IApplicationGateway.Inner.UrlPathMaps.PathRules

检索可用值

我基本上想要这个: 但不能通过 Azure CLI 或 PowerShell。

我期待类似这样的结果:https://docs.microsoft.com/en-us/cli/azure/network/application-gateway/url-path-map?view=azure-cli-latest

如果您想使用包 Microsoft.Azure.Management.Fluent 更新 Azure Application Gateway,请参考以下步骤

  1. 创建服务主体并将 Contributor 角色分配给 sp
az login
az ad sp create-for-rbac -n "MyApp" --sdk-auth
  1. 代码
string clientId = "";
            string clientSecret = "";
            string tenantId = "";
            string subscriptionId = "";
            var credentials = SdkContext.AzureCredentialsFactory
                .FromServicePrincipal(clientId,
                    clientSecret,
                    tenantId,
                    AzureEnvironment.AzureGlobalCloud);

            var groupName = "testgateway";
            var name = "gateway";
            var restClient =RestClient.Configure()
                .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                .WithCredentials(credentials)
                .Build();
            NetworkManagementClient networkClient = new NetworkManagementClient(restClient);
            networkClient.SubscriptionId = subscriptionId;
            var gateway = await networkClient.ApplicationGateways.GetAsync(groupName, name);
            ApplicationGatewayUrlPathMapInner[] rules = gateway.UrlPathMaps.ToArray();
            // update one rule 
            foreach (ApplicationGatewayUrlPathMapInner rule in rules) {
               var pathRule= rule.PathRules.ToArray().Where(item => item.Name == "Video").FirstOrDefault();
                pathRule.Paths = new List<string> { "/myvideo/*" };
            }

           await networkClient.ApplicationGateways.CreateOrUpdateAsync(groupName, name, gateway);