asp.net core设置跨域

   public void ConfigureServices(IServiceCollection services)
        { var urls = AppConfigurtaionServices.Configuration.GetSection("Cors")["default"].Split(',');
            services.AddCors(options =>
            options.AddPolicy("AllowSameDomain",
            builder => builder.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials())
            );
        }

appsetting中加入   

"Cors": {

    "default": "http://localhost:24154/"

  }

允许跨域访问的api控制器上面加上[EnableCors("AllowSameDomain")]这个特性即可


需要引用:Microsoft.AspNetCore.Cors


你可能感兴趣的:(Core,2.0)