AngularJS +的ASP.NET Web API跨域问题 [英] AngularJS + ASP.NET Web API Cross-Domain Issue
问题描述
我的移动应用程序开发学习过程展望未来,我已经找到了一个新的障碍:跨域请求共享或CORS
Moving forward with my mobile app development learning process, I've found a new obstacle: Cross-origin Request Sharing or CORS.
我使用AngularJS + jQuery Mobile的(科尔多瓦手机客户端)和ASP.NET Web API(后端)的组合。我的问题是,我一直没能完成一个POST请求(或任何其他类型的请求)到API控制器。
I am using a combination of AngularJS + jQuery Mobile (Cordova phone client) and ASP.NET Web API (backend). My issue is that I have not been able to complete a POST request (or any other type of request) to an API controller.
我AngularJS控制器使用 $ http.post()
服务方法调用Web API控制器。然而,Chrome的调试器说,该呼叫在OPTIONS请求(可能是CORS preflight请求)失败。
My AngularJS controller uses the $http.post()
service method to call the Web API controller. However, Chrome debugger says that the call failed in an OPTIONS request (possibly the CORS preflight request).
我已经实现从以下职位的CORS动作选择:的在网页API项目启用CORS。即使是艰难的,我可以从提琴手调用API方法,AngularJS一直在OPTIONS preflight请求失败。
I have implemented the CORS action selector from the following post: Enabling CORS in Web API Project. Even tough I can call the api method from Fiddler, AngularJS keeps failing on the OPTIONS preflight request.
有什么我应该知道的关于AngularJS和跨域调用?任何可能的解决我的predicament?
Is there anything I should be aware of about AngularJS and cross-domain calls? Any possible solution to my predicament?
感谢。
推荐答案
在此之后,我发现,pretty多地址此方案的文章。 下面是文章。
Following up on this, I found an article that pretty much address this scenario. Here is the article.
这篇关于AngularJS +的ASP.NET Web API跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!