本文主要是介绍【ASP.NET】 No 'Access-Control-Allow-Origin' header is present on the requested resource.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前端JS用XMLHttpRequest,请求后端数据。出现了No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
我是使用的ASP.NET框架。
解决办法:
在Web.config文件相应地方添加:
<?xml version="1.0" encoding="utf-8"?>
<configuration><configSections><system.webServer><httpProtocol><customHeaders><add name="Access-Control-Allow-Origin" value="*" /><add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" /><add name="Access-Control-Allow-Headers" value="Content-Type, soapaction" /></customHeaders></httpProtocol></system.webServer>
</configuration>
这篇关于【ASP.NET】 No 'Access-Control-Allow-Origin' header is present on the requested resource.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!