asp.net core 3.1 webapi 跨域解決辦法


利用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跨域模塊。

程序內部異常或錯誤也會報出跨域的問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM