1.在 Web.config 文件中添加以下代码,允许跨域请求:
2.使用 JSONP 跨域请求。
3.在 Web API 项目的 Register 方法中添加以下代码:
var cors = new EnableCorsAttribute("", "", "*"); config.EnableCors(cors);
4.在服务器端设置 CORS 响应头:
HttpContext.Current.Response.Headers.Add("Access-Control-Allow-Origin", "*");
上一篇:Asp.net向Golang迁移