azure - 如何访问 Azure API 管理中的路由参数

标签 azure azure-api-management

查询字符串参数

我见过很多读取查询字符串参数的示例。

例如,采用以下 URI:

/api/Profile?id={accountId}

可以使用以下语法在策略 xml 中读取 accountId:

context.Request.Url.Query["accountId"]

路由参数

但是如果我的 URI 结构如下:

/api/profiles/{accountId}

当参数不在查询字符串中时,如何读取策略 xml 中的 accountId

最佳答案

使用上面的示例,我可以读取 accountId通过以下语法:

context.Request.MatchedParameters["accountId"]

例如,我可以将其分配给一个变量,以便在 APIM 策略文件中的其他位置使用:

<set-variable name="account-id" value="@(context.Request.MatchedParameters["accountId"])" />

关于它的文档并不多,但幸运的是至少有 some mention of the Context variable在 learn.microsoft.com 上。

关于azure - 如何访问 Azure API 管理中的路由参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60548557/

相关文章:

azure-api-management - Azure Api 管理是否可以禁用订阅 key

authentication - 使用 user/pass 向 web.config 添加基本身份验证的最简单方法

azure - 使用 Rest API 在 Azure Devops 中创建工作项时出错

azure - 如何检查azure api管理策略表达式中的请求正文是否为空?

azure - Kustos bag_unpack 不解压我的 json 字典字符串

powershell - 具有 Web 应用程序槽端点的流量管理器

api - Azure API 管理始终返回 404 未找到资源

yaml - 在 API 管理前端中保存 Swagger 文档时缺少架构

Azure AD 应用程序注册将重定向 URI 限制为 256

Azure Function ExecutionContext.InitationId 与 FunctionFilterContext.FunctionInstanceId