【问题标题】:Azure API Management Conditional outbound headersAzure API 管理条件出站标头
【发布时间】: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


【解决方案1】:

CORS Policy 允许列出多个允许的来源,并根据请求处理响应标头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-23
    • 2018-07-31
    • 1970-01-01
    • 2020-07-28
    • 2016-06-09
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    相关资源
    最近更新 更多