跨域访问限制? [英] Cross domain access restrictions ?

查看:78
本文介绍了跨域访问限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XMLHttpRequest cannot load "dev server deployed Web Api". No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '""' is therefore not allowed access





我使用WebApi,HTML,JS,AngularJS,CSS,Bootstrap构建应用程序。

通过Ajax在Javascript中调用Api。我们使用CMS并将HTML转换为冷融合中的自定义资源(只需将.html更改为.cfm)。该自定义资产位于生产服务器中。



现在Api部署在生产服务器中部署的开发服务器和UI代码文件中,该服务器试图从开发服务器访问Api。





请给我一些解决方案,我该如何解决这个问题。



我尝试了什么:



Dev Api url尝试在生产服务器浏览器,本地浏览器和开发服务器浏览器中工作。但是当我运行生产部署的应用程序时,我可以在字段中看到UI但没有Api数据。



I build the application using WebApi, HTML, JS, AngularJS, CSS, Bootstrap.
Consuming Api via Ajax call in the Javascript. We use a CMS and convert the HTML to custom asset in cold fusion(just change the .html to .cfm). That custom asset is in Production server.

Now the Api is deployed in the dev server and UI code files deployed in Production server which is trying to access the Api from dev server.


Please give me some solution, how can I fix this issue.

What I have tried:

Dev Api url tried in Production server browser, local browser, and dev server browser works every where. But when I run the production deployed application I can see the UI but no Api data in the fields.

推荐答案

在WebApiConfig中添加启用CORS配置

在Register下我添加了这段代码。

Added Enable CORS configuration in WebApiConfig
Under Register I have added this code.
var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);


这篇关于跨域访问限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆