用于 XmlHttpRequest 的带有 WebAPI 的 CORS [英] CORS with WebAPI for XmlHttpRequest

查看:21
本文介绍了用于 XmlHttpRequest 的带有 WebAPI 的 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道在 ASP.NET WebAPI 中处理 CORS(跨源资源共享)的最佳优雅方式(当前可用)是什么,以便我可以在多个域上使用 XmlHttpRequest?我如何将它集成到每种类型的请求(GET、POST 等)的标头中也可以使用 OPTIONS?

Just wanted to know what is the best elegant way (currently available) to handle CORS (Cross-Origin Resource Sharing) in ASP.NET WebAPI so i can use XmlHttpRequest over multiple domains ? How i can integrate this in the headers of every type of request (GEt, POST, etc..) with OPTIONS too ?

谢谢!

推荐答案

Tpeczek 有一个不错的发现,但是在我自己的研究中,我发现了一些类似且非常优雅的处理 CORS 的方法,使您能够在App_Start 文件夹中的配置文件.它全部使用一个名为 Thinkecture 的开源库处理.在此处查看详细信息:

Tpeczek have a nice found, however while doing my own research ive found something similar and also very elegant ways of handling CORS which enable you to configure your CORS in a config file in App_Start folder. Its all handled using an open source library called Thinkecture. See details here :

http://brockallen.com/2012/06/28/cors-support-in-webapi-mvc-and-iis-with-thinktecture-identitymodel/

它有很多优点.您可以配置来源、方法(GET、POST 等)、对特定控制器和操作的访问,它还可以使您的控制器免受任何属性的影响.

It have many advantages.. you can configure origins, methods (GET, POST, etc.), access to specifics controllers and actions and it also keep your controllers clean from any attributes.

支持 WebAPI、IIS 和 ASP.NET MVC!

WebAPI, IIS and ASP.NET MVC is supported !

这篇关于用于 XmlHttpRequest 的带有 WebAPI 的 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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