webapi跨域解决方案

服务器添加响应头跨域

1.进入服务器端IIS,打开相应头设置
webapi跨域解决方案

  1. 添加响应头
    Access-Control-Allow-Origin:*
    Access-Control-Allow-Methods:*

服务器端代码跨域

  1. 选择工具,管理解决方案的NuGet程序包
    webapi跨域解决方案
  2. 搜索并安装 Microsoft.AspNet.WebApi.Cors
    webapi跨域解决方案
  3. 在WebApiConfig.cs的Register函数中增加
      config.EnableCors(new EnableCorsAttribute("*", "*", "*"));