使用 Azure APIM 策略获取策略中指定的 url 部分

Pin*_*ong 4 azure azure-api-management

是否可以在策略内获取下面指定的 url 部分:

<policies>
        <inbound>
            <base />    
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
            <find-and-replace from="https://thirdparty/certs" 
                 to="@(specified url part)" />        
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>
Run Code Online (Sandbox Code Playgroud)

请注意,整个 URL 可能包含版本控制和前缀。

Vit*_*tin 11

整个 URI(假设https://contoso.com/myapi/.wellknown/openid-config)由以下部分组成:

  1. 方案:context.Request.OriginalUrl.Scheme
  2. 主持人:context.Request.OriginalUrl.Host
  3. 可选端口:context.Request.OriginalUrl.Port
  4. API后缀:context.Api.Path
  5. 操作路径:其余

所以 URL 的操作部分可以通过类似的方式计算:context.Request.OriginalUrl.Path.Trim('/').Substring(context.Api.Path.Trim('/').Length)