Azure API管理:替换querystring参数名称

时间:2019-04-05 22:54:35

标签: url-rewriting azure-api-management

APIM的新功能。尝试使用后端api期望的其他名称更改公开的查询字符串参数名称(而不是值)

例如,APIM端点需要/ v1 / Customer?CustomerId = 123

我认为我需要在入站部分使用rewrite-url策略吗?

要将其更改为此:/ v1 / Customer?ExternalCustomerId = 123


尝试此操作不起作用

<set-query-parameter name="ExternalCustomerId" exists-action="append">
        <value>@(Context.Request.QueryString["CustomerId"])</value>
    </set-query-parameter>

错误:名称“上下文”在当前上下文中不存在

2 个答案:

答案 0 :(得分:1)

尝试使用小写的“上下文”。加上QueryString是一个IReadOnlyDictionary,如此处所述:https://docs.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ContextVariables,但有一个方便的重载:

<set-query-parameter name="ExternalCustomerId" exists-action="append">
    <value>@(context.Request.QueryString.GetValueOrDefault("CustomerId"))</value>
</set-query-parameter>

答案 1 :(得分:0)

截至2019年9月,此更改已更改。现在使用以下内容:

Project