js客户端跨域访问webapi报Access-Control-Allow-Origin的问题

js客户端跨域访问webapi报

XMLHttpRequest from origin has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource) 

看到这个问题已为很好解决,就是跨越的问题,在webapi,startup.cs里加上允许跨域的设置就行,结果失败了。

 

后来在网上找到解决办法,静态资源请求也受到了跨域的限制,将app.useCors放到app.UseStaticFiles()之前就可以了。

 

posted @ 2022-08-10 11:25  hello_stone  阅读(308)  评论(0)    收藏  举报