在 Azure API 管理入站策略部分获取路由参数

Cha*_*han 4 azure azure-api-management

我有一个带有模板参数的 URL。

https://test.azure-api.net/HelperFunction/{siteId}/lots/InventoryItem/{itemId}
Run Code Online (Sandbox Code Playgroud)
https://test.azure-api.net/HelperFunction/122/lots/InventoryItem/12
Run Code Online (Sandbox Code Playgroud)

我想阅读入站策略部分中的模板/路径参数。

我正在尝试如下。但它只会获取查询字符串参数。我想获取路径参数。

 <inbound>
        <set-body>@{
                JObject transBody = new JObject();
                transBody.Add("Arguments", 
                new JObject
                {
                    {"method", context.Request.Method},
                    {"parameters", context.Request.Url.QueryString},
                });

                //Add all json properties as arg
                transBody.Add("UriPath", context.Request.Url.Path);
                return transBody.ToString();
            }</set-body>
        <base />
 </inbound>
Run Code Online (Sandbox Code Playgroud)

我的要求是将路由参数读取为

"siteId" : 122,
"itemId" : 12
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

Vit*_*tin 6

context.Request.MatchedParameters["siteId"]context.Request.MatchedParameters["itemId"]

上下文变量的其余部分可以在这里找到: https: //learn.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables