为Web API启用多个CORS [英] Enabling multiple CORS for Web API

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

问题描述

我有一个编写的Web API和一个使用它的应用程序。因此,我通过在API的控制器类中添加标头,为该应用程序添加了CORS标头:

I have a Web API I wrote and one application utilizing it. SO I added CORS header for that applicaiton by adding a header to the controller class within my API:

[EnableCors(origins: "http://localhost:59452", headers: "*", methods: "*")]

以上工作正常。现在,我还希望有更多使用该Web API的应用程序。我的问题是我该如何实现?

The above worked fine. Now I also want more applications consuming that web API. My question is how do I make this happen?

推荐答案

您可以通过用逗号分隔多个来源来添加它们:

You can add multiple origins by separating them with commas:

[EnableCors(origins: "http://localhost:59452,http://localhost:25495,http://localhost:8080", headers: "*", methods: "*")]

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

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