简体   繁体   English

在Web API中启用CORS时,“ *”中允许使用哪些HTTP方法

[英]which http methods allowed in “*” when enabling CORS in web api

I have implemented CORS in web API by using Cors library. 我已经通过使用Cors库在Web API中实现了CORS。

   [EnableCors(origins: "*", headers: "*", methods: "*")]

and in webapi config file 并在webapi配置文件中

       config.EnableCors();

I called api using POST method, still I was getting error in console i:e No 'Access-Control-Allow-Origin' header is present on the requested resource. 我使用POST方法调用api,但仍然在控制台i中出错:e请求的资源上没有'Access-Control-Allow-Origin'标头。

Then I changed 然后我改变了

      [EnableCors(origins: "*", headers: "*", methods: "*")]

To

     [EnableCors(origins: "*", headers: "*", methods: "GET, POST, PUT, DELETE, OPTIONS")]

Then its started working, my question why it doesn't work with allowed methods using "*" 然后它开始工作,我的问题是为什么它不能与使用“ *”的允许方法一起工作

The wildcard for Access-Control-Allow-Methods is not yet supported by all browsers. 并非所有浏览器都支持Access-Control-Allow-Methods通配符。

  • Chromium-based browsers should support it ( issue 615313 ) 基于铬的浏览器应支持它( 发行615313
  • Firefox does not yet support it ( bug 1309358 ) Firefox尚不支持它( 错误1309358
  • IE probably doesn't support it and Edge possibly does not support it yet. IE可能不支持它,Edge可能还不支持它。 Edge is moving to the Chromium engine in the future, so they'll support it at some point. Edge将来会迁移到Chromium引擎,因此他们会在某个时候提供支持。

Browser support is also tracked by MDN here , so future readers may want to check that too in case this answer becomes outdated. 浏览器支持也由MDN跟踪在这里 ,所以未来的读者可能要检查过的情况下,这个答案变得过时。

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

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