简体   繁体   English

启用CORS不在全球范围内工作

[英]Enable CORS not working globally

In my Web API project I have enabled CORS globally by adding following line in WebApiConfig 在我的Web API项目中,我通过在WebApiConfig添加以下行来全局启用了CORS

config.EnableCors();

but it still give me error while I request service from other App Domain. 但是当我从其他App Domain请求服务时,仍然给我错误。

However it works fine if I apply [EnableCors("*", "*", "*")] on controller level. 但是,如果我在控制器级别应用[EnableCors("*", "*", "*")] ,它会很好地工作。

Why it doesn't work for application level? 为什么它不适用于应用程序级别?

If you want to define a global rule, you can pass that into EnableCors : 如果要定义全局规则,可以将其传递给EnableCors

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);

By calling EnableCors , you just enable the framework, nothing more. 通过调用EnableCors ,您只需启用框架,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM