【发布时间】:2021-08-03 18:52:28
【问题描述】:
我正在使用 API 管理设置出站标头,到目前为止,使用此策略块的单个域已经足够了
<outbound>
<base />
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example.com</value>
</set-header>
</outbound>
但是,我现在需要根据已批准的域列表来管理 Access-Control-Allow-Origin 的多个域。我曾尝试使用条件块,但这不起作用。
<outbound>
<base />
<choose>
<when condition="@(context.Request.OriginalUrl.Host == "example.com")">
<return-response>
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example.com</value>
</set-header>
</return-response>
</when>
<when condition="@(context.Request.OriginalUrl.Host == "example1.com")">
<return-response>
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example1.com</value>
</set-header>
</return-response>
</when>
<otherwise />
</choose>
</outbound>
如果请求中的域与列表匹配,我们需要处理的域列表不断增加,以便将带有标头的响应发送回客户端。有没有更好的方法来处理这个问题,我怎样才能做到这一点?
【问题讨论】:
-
您不能使用 APIM 的 CORS 政策的任何特殊原因?
标签: azure cors azure-api-management