Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure API管理:如何在标头中设置对象id?_C#_Azure_Azure Api Management - Fatal编程技术网

C# Azure API管理:如何在标头中设置对象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

我正在使用Azure广告B2C、Azure API管理和Azure功能

当客户端向APIM发送HTTP请求时,该用户的访问令牌将在标头中设置

我想写一个APIM策略,它从访问令牌中提取对象id并在头中设置它

我的政策如下:

<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”,“”)