如何在 C# 中为 Azure 应用程序网关创建基于路径的路由规则?

How do I create path-based routing rules for Azure Application Gateway in C#?

在 Azure 门户中,我使用基于路径的路由手动创建了一个应用程序网关。现在我需要在 C# 中自动执行此操作。我似乎找不到任何方法来创建基于路径的路由规则。我正在使用 Microsoft.Azure.Management.Fluent 包。我错过了什么?

如果 Fluent API 不支持,是否有 REST 替代方案?

例如:

var appGw = Azure.ApplicationGateways.Define(AppGwName)
    .WithRegion(Region)
    .WithExistingResourceGroup(resourceGroup)
    .DefineRequestRoutingRule("default") 
    // Now what?

我可以在 github 中找到与此相关的 path-based routing settings in the Microsoft.Azure.Management.Fluent package, but cannot find a way to configure it. And there is an issue

但它绝对可以使用 Microsoft.Azure.Management.Network 包创建 Application Gatewaypath-based routing settings

这是一个例子:

        ApplicationGateway gateway = new ApplicationGateway();

        //configure thepath-based routing.
        ApplicationGatewayRequestRoutingRule r = new ApplicationGatewayRequestRoutingRule();
        r.RuleType = ApplicationGatewayRequestRoutingRuleType.PathBasedRouting;
        gateway.RequestRoutingRules.Add(r);

        //configure other settings.
        //gateway.Location = "xxx";

        gateway.Validate();

        //create the gateway.
        NetworkManagementClient networkManagementClient = new NetworkManagementClient(your_credential);
        networkManagementClient.ApplicationGateways.CreateOrUpdate("resource group name", "application gateway name", gateway);

参考代码示例:here and here.

关于api,可以参考Create Application Gateway。在请求正文中,它定义了 path-based routing settings.