【发布时间】:2014-12-12 08:17:38
【问题描述】:
我们正在对 ASP.NET WebApi 2.2 进行跨站点请求。我们在WebApiConfig 中启用了 CORS:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("http://www.mydomain.ca", "*", "*");
config.EnableCors(cors);
}
}
这在 LIVE 网站上运行良好。在开发过程中,我们需要更宽松的 CORS 设置,因为我们在 IIS 中同时托管来自多个开发环境的 WebService 和 WebClient。 IE。我们需要 new EnableCorsAttribute("*", "*", "*"); 在开发框和 LIVE 时的受限来源。
我们如何在开发和实际环境中自动从许可 CORS 切换到限制 CORS?
【问题讨论】:
标签: asp.net asp.net-web-api cors