【问题标题】:Is there a difference between the <cors> tag in web.config and this httpProtocol with Custom Header?web.config 中的 <cors> 标记与带有自定义标头的 httpProtocol 之间有区别吗?
【发布时间】:2021-12-28 20:02:58
【问题描述】:

目前在 ASP.NET Core MVC 应用程序中,我将以下 web.config 添加到站点:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <cors enabled="true">
            <add origin="*" />
        </cors>
    </system.webServer>
</configuration>

但我收到一些客户需要将我的 cors 标签替换为以下内容的反馈:

        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
        </httpProtocol>

我想知道它们在功能上有何不同?在我看来,它们会产生相同的结果,但在实践中似乎并非如此。

编辑:我确实想知道问题是否是其中一些服务器缺少 IIS Cors 模块。阅读MSDN Documentation for the cors tag 似乎等同于每个编写的第二个选项。

【问题讨论】:

    标签: asp.net-mvc iis cors web-config


    【解决方案1】:

    对于最简单的情况,这两种方法是等效的,但在复杂的情况下,它们会产生完全不同的结果,尤其是当您的 Web 应用程序受 Windows 身份验证保护时。

    &lt;cors&gt; 作为 IIS CORS 模块的一部分允许您在这种情况下进行配置,而如果您选择自定义响应标头,则完全由您自己决定。

    【讨论】:

      猜你喜欢
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 2016-04-05
      • 2017-12-28
      • 2011-03-03
      • 2014-02-18
      相关资源
      最近更新 更多