VisualStudio中的CORS(角度应用程序)
几个小时来我一直在为这件事发愁。我正在学习Angular并尝试编写一个在家庭自动化服务器(Indigo)中使用API的应用程序。每当我试着打电话给RESTAPi的其中一个,我都会得到:VisualStudio中的CORS(角度应用程序),cors,web-config,Cors,Web Config,几个小时来我一直在为这件事发愁。我正在学习Angular并尝试编写一个在家庭自动化服务器(Indigo)中使用API的应用程序。每当我试着打电话给RESTAPi的其中一个,我都会得到: HTML1300: Navigation occurred. File: index.html Main Controller Startup... SEC7118: XMLHttpRequest for http://192.168.168.157:8176/devices// required Cro
HTML1300: Navigation occurred.
File: index.html
Main Controller Startup...
SEC7118: XMLHttpRequest for http://192.168.168.157:8176/devices// required Cross Origin Resource Sharing (CORS).
File: index.html
SEC7120: Origin http://localhost:50441 not found in Access-Control-Allow-Origin header.
File: index.html
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.
File: index.html
Error: ; 0
我已将以下内容添加到我的web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
有人知道我需要做些什么才能让它工作吗
谢谢
马克所以,我让它工作了
结果证明这与本地asp.net服务器无关。我试图连接的服务器是用CherrPy编写的。我所要做的就是添加
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
显然,一旦我完成测试,我将进一步限制它
问候
标记您是否在开发工具中看到标题?您正在运行哪台服务器?@mpm感谢您的回复。我应该寻找哪个标题?我猜是IIS,因为它是VisualStudio用于调试的服务器。API正在连接到第三方应用程序。但我认为我的问题在于运行angualar应用程序的web服务器。这些是API请求的标题:请求URL:请求标题警告:显示临时标题。Accept:application/json,text/plain,/Cache-Control:no-Cache-Origin:Pragma:no-Cache-Referer:User-Agent:Mozilla/5.0(windowsnt 6.1;WOW64)AppleWebKit/537.36(KHTML,比如Gecko)Chrome/35.0.1916.153 Safari/537.36
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'