C# Azure API管理:如何在标头中设置对象id?
我正在使用Azure广告B2C、Azure API管理和Azure功能 当客户端向APIM发送HTTP请求时,该用户的访问令牌将在标头中设置 我想写一个APIM策略,它从访问令牌中提取对象id并在头中设置它 我的政策如下:C# Azure API管理:如何在标头中设置对象id?,c#,azure,azure-api-management,C#,Azure,Azure Api Management,我正在使用Azure广告B2C、Azure API管理和Azure功能 当客户端向APIM发送HTTP请求时,该用户的访问令牌将在标头中设置 我想写一个APIM策略,它从访问令牌中提取对象id并在头中设置它 我的政策如下: <inbound> <set-header name="objectId" exists-action="override"> <value>@(((Jwt)context.Variabl
<inbound>
<set-header name="objectId" exists-action="override">
<value>@(((Jwt)context.Variables["jwt"]).Claims["sub"])</value>
</set-header>
</inbound>
@(((Jwt)context.Variables[“Jwt”]).Claims[“sub”])
但是,此代码引发了一个错误:无法将类型“string[]”隐式转换为“string”
我认为您应该使用(如果未找到标头,则返回逗号分隔的声明值或defaultValue)。因为索赔是一个数组
试试这个
<inbound>
<set-header name="objectId" exists-action="override">
<value>@(((Jwt)context.Variables["jwt"]).Claims.GetValueOrDefault("sub", ""))</value>
</set-header>
</inbound>
@((Jwt)context.Variables[“Jwt”]).Claims.GetValueOrDefault(“sub”,“”)