通过Azure APIM策略获取基本URL及其带有版本标识符的URL

时间:2019-07-10 15:59:10

标签: azure azure-api-management

是否有可能在策略范围内获取基本URL以及以下突出显示的版本的URL: enter image description here 需要一个网址,如下所示:

find-and-replace

在以下 <policies> <inbound> <base /> <set-backend-service base-url="https://my.com/oidc" /> </inbound> <backend> <base /> </backend> <outbound> <base /> <find-and-replace from="https://thirdparty/certs" to="@(base url with version identifier)/certs" /> </outbound> <on-error> <base /> </on-error> </policies> 元素中使用上方:

{{1}}

更新

我也如何获得基本网址?原因是有时未指定版本化的url,在这种情况下,仅使用基本url进行替换。

https://docs.microsoft.com/en-us/azure/api-management/api-management-policy-expressions#ref-iurl

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码段获取带有版本的基本网址

@{
     var methodRoute = context.Request.Url.ToString().Replace(context.Api.ServiceUrl.ToString(),"");
     var frontEndServiceUrl = context.Request.OriginalUrl.ToString().Replace(methodRoute,"");
}
相关问题