通过 Azure APIM Policy 获取 Base URL 和带有版本标识符的

Get Base URL and that with version identifier via Azure APIM Policy

是否有可能在政策范围内获得基础 url 以及下面突出显示的版本: 需要一个 url,如下所示:

@(base url with version identifier)

上面的内容用在下面的 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>

更新

我怎样才能得到基础 url?原因是有时候,没有指定版本url,在这种情况下,只使用基础url来替换。

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

您可以使用下面的代码片段

获取带有版本的基础url
@{
     var methodRoute = context.Request.Url.ToString().Replace(context.Api.ServiceUrl.ToString(),"");
     var frontEndServiceUrl = context.Request.OriginalUrl.ToString().Replace(methodRoute,"");
}