解决方法:

ajax 跨域请求前台处理,红色字段为ajax处理跨域属性

$.ajax({
    url:"http://citygame1234.4kb.cn/CityServer/w/login",
    type:"post",
    async:"false",
    dataType:"json"    crossDomain: true,
    xhrFields: {
        withCredentials: true
    },
    success:function(data){
        console.log(data);
    }
});

.net core配置

在Startup.cs类 的ConfigureServices方法加入如下代码:

        services.AddCors(options =>
            {
                options.AddPolicy("AllowAllHeaders",
                      builder =>
                      {
                          builder.WithOrigins("http://localhost:63342",
                                "https://localhost:44395")
                                 .AllowAnyMethod()
                                 .AllowAnyHeader()
                                 .AllowCredentials();
                      });
            });

 

在Configure方法加入如下代码:
 app.UseCors("AllowAllHeaders");

  

相关文章:

  • 2021-09-24
  • 2021-08-31
  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2020-04-07
  • 2021-05-02
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案