一、使用System.Web.Http.Cors配置跨域访问:
1、在App_Start/WebApiConfig.Register方法中进行配置
//Web API 配置和服务
//跨域配置
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));//全部不限制
参数说明:
origins:允许访问的域名,多个域名以逗号分隔。使用“*”全部允许。
headers:配置所支持的资源,使用“*”全部允许,使用null或“”不允许。
methods:配置支持的请求方法,使用“*”全部允许,使用null或“”不允许。
config.EnableCors(new EnableCorsAttribute("http://localhost:1234/,http://localhost:2345/", "*", "*"));//限制域名
2、在Web.config中进行配置
<system.webServer>
<httpProtocol>
<customHeaders>