[英]Policy rewrite-uri To Append Context Variable in Azure APIM
在策略重写期间将简单附加到上下文变量(例如context.Variables["accountKey"]
的 url 的方法是什么?
最终结果应该是/accounts/232
。
我在设置它之前取得了成功
set-variable (0.003 ms)
{
"message": "Context variable was successfully set.",
"name": "accountKey",
"value": "232"
}
尝试过的一件事:
<policies>
<inbound>
<base />
<rewrite-uri template="/accounts/{accountKey}" />
</inbound>
但我收到这个错误
> Error Receive
> rewrite-uri (0.260 ms) {
> "messages": [
> null,
> "Variable accountKey has no value.",
> "Variable accountKey has no value."
> ] }
在策略中配置入站规则如下:
<inbound>
<base />
<set-variable name="accountKey" value="232" />
<rewrite-uri template="@{
return "/account/" + context.Variables.GetValueOrDefault<string>("accountKey");
}"/>
</inbound>
rewrite-uri 中的 {} 用于原始请求 URL 中的查询字符串参数。
在重写 URL - API 管理转换策略的 Microsoft 文档中查找有关 rewrite-uri 部分的更多详细信息。
我最终使用此调用作为替代方法:
<rewrite-uri template="@($"/account/{(string)context.Variables["accountKey"]}/")" />
就我而言,我的网址是
https://test.com/send/
我需要从上下文变量名称中添加查询字符串(名称 = myName
)
https://test.com/send/myName
这对我有用:
<rewrite-uri template="@($"{(string)context.Variables["name"]}")" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.