Azure API 管理策略 - 动态命名值 select
Azure API Management Policy - Dynamic named value select
我已经根据用户 ID 存储了一个命名值,因此我可以根据我选择的参考来识别负载提交者。
当我使用下面的策略时,我得到的是字符串形式的值,而不是实际查找指定的值。如果我只是将用户 ID 写在双花括号内而不是从上下文中动态获取它,查找工作正常并且它替换为我想要的命名值。
不可以简单的做吗?
<policies>
<inbound>
<set-header name="x-request-context-data" exists-action="override">
<value>{{@(context.User.Id)}}</value>
</set-header>
</inbound>
</policies>
输出:
x-request-context-data: {{@(context.User.Id)}}
已在 MSDN 回答。
While you can use named values in policy expressions, the other way
around is not supported and not possible to support as described in
this feature request.
Workarounds would be to either
- Store named values as a JSON string or a CSV string with key=value pairs. Then use policy expressions to parse and fetch the required value.
- Use control flow policies for run time decisions.
- For complex cases, offload to a function app but use value caching policies for improved latency if possible
我已经根据用户 ID 存储了一个命名值,因此我可以根据我选择的参考来识别负载提交者。
当我使用下面的策略时,我得到的是字符串形式的值,而不是实际查找指定的值。如果我只是将用户 ID 写在双花括号内而不是从上下文中动态获取它,查找工作正常并且它替换为我想要的命名值。
不可以简单的做吗?
<policies>
<inbound>
<set-header name="x-request-context-data" exists-action="override">
<value>{{@(context.User.Id)}}</value>
</set-header>
</inbound>
</policies>
输出:
x-request-context-data: {{@(context.User.Id)}}
已在 MSDN 回答。
While you can use named values in policy expressions, the other way around is not supported and not possible to support as described in this feature request.
Workarounds would be to either
- Store named values as a JSON string or a CSV string with key=value pairs. Then use policy expressions to parse and fetch the required value.
- Use control flow policies for run time decisions.
- For complex cases, offload to a function app but use value caching policies for improved latency if possible