利用asp.net core 3.1 開發了一個webapi,部署在IIS時,出現如下錯誤:
Access to fetch at 'XXXXX' from origin 'http://xxxxxxx:xxxx' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.
在Startup.cs 的ConfigureServices和Configure都進行了跨域設置,具體的設置,微軟官方文檔說明的比較詳細。
https://docs.microsoft.com/zh-cn/aspnet/core/security/cors?view=aspnetcore-3.1
部署在IIS依然有跨域問題,還是在上面微軟官方文檔里面找到了解決辦法:需要安裝IIS Cors跨域模塊。
程序內部異常或錯誤也會報出跨域的問題。