cors - Web API 2 CORS 不允许 IP 地址作为来源

标签 cors asp.net-web-api2

我有一个启用了 CORS 身份验证的 Web API 2 应用程序。在本地,我正在运行两个站点,一个 SPA 站点和一个 Web API,两者都在端口 80 上,使用不同的主机 header 。一切正常。但是,我尝试在没有域的计算机上进行测试,因此我必须对两个站点使用具有不同端口的 IP 地址。无论我做什么,Web API 都会给出旧的“请求的资源上不存在‘Access-Control-Allow-Origin’ header 。因此不允许访问 Origin ' http://xxx.xxx.xxx.xxx:8090 '”。我的 CORS 配置如下:

var cors = new EnableCorsAttribute(
            origins: "*",
            headers: "*",
            methods: "*");
        config.EnableCors(cors);

是否只有当 API 位于真实域而不是 IP 地址时才可以运行 Web API 2 CORS?这似乎是一个极端的限制。

不确定这是否重要,但在本地我运行的是 IIS 7.5,但我的测试机器是 IIS 7。

任何帮助将不胜感激。

最佳答案

结果是 IIS 特定的。当我将 API 放到运行 IIS 7.5 的机器上时,它就完美地工作了。干杯。

关于cors - Web API 2 CORS 不允许 IP 地址作为来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878706/

相关文章:

java - Jhipster CORS 启用

不允许使用 CORS 405 方法

reactjs - 来自 CORS 预检 channel 的 CORS header ‘x-auth’ 中缺少 token ‘Access-Control-Allow-Headers’

spring - 浏览器未连接到 Springboot Websocket (sockjs)

c# - 包括属性(property)但排除该属性(property)的属性(property)之一

angular - 使用 Google Auth、Angular 4、ASP.Net Core 2 进行身份验证时出现 405

asp.net-web-api - 如何在到达 Web Api Controller 之前过滤请求响应

c# - 覆盖 ModelState 非常技术性的错误消息

c# - 防止公共(public)服务过度使用

iis-7.5 - 使用虚拟目录/应用程序在 IIS 中托管 ASP.NET 5 WebAPI