Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*'

       记一次在.net core接口开发中遇到的此问题解决之路。

       很奇怪,之前一直运行正常的接口及系统,现在突然报此错误,度娘了很久也没发现好的解决办法。后来在国外网站里面找到了解决办法。下面截图是具体错误:

 

 

        在Startup.cs文件中的Configure方法中,增加这么一个设置就可以解决了:

app.UseCors(builder => builder.WithOrigins("http://localhost:8003")   // 此处是数组,可以输入多个地址
   .AllowAnyMethod()
   .AllowCredentials()
   .AllowAnyHeader());

 

posted @ 2021-03-08 14:32  中级菜鸟  阅读(2729)  评论(0编辑  收藏  举报