Angular 当引用 https 服务器上的 css 文件时,获取 CORS No Access-Control-Allow Origin

Angular getting CORS No Access-Control-Allow Origin when references css file on a https server

我有一个带有 Web api 后端的 Angular 5 应用程序,但是我只想在生产服务器上引用一个 CSS 文件。

我该怎么做才能避免跨源问题(网络上启用了 cors api,但它不是网络 api,它只是一个 CSS 文件IIS 服务器网站。

Access to Font at 'https://prodserver/Content/Styles/fonts/icomoon.ttf?53j0gm' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' ...

我试图在我的 angular 应用程序中使用 CORS,它与网络 api cors 无关,而且我没有使用节点,

这简直就是CSS ...

您需要在 BE 端启用 CORS

对于 Web Api 检查

Web Api Cors

[EnableCors(origins: "http://localhost:4200", headers: "*", methods: "*")]

您需要为 CORS 配置 Web 服务器。您包含的错误不是针对 CSS,而是针对字体。字体在某些浏览器上受 CORS 限制

https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy