ABP(AspNet Boilerplate)API的间歇性CORS策略问题

问题描述 投票:0回答:1

ASP.NET零(.Net Core v2 + Angular v5)

AbpUserConfiguration / GetAll有时会中断,在处理了很少的请求后,它有时会开始生成跨域问题,因此效果很好。

以下为错误。

已从CORS策略阻止从原点[http://localhost:22743/AbpUserConfiguration/GetAll'访问'http://localhost:4200处XMLHttpRequest:在所请求的资源上没有'Access-Control-Allow-Origin'标头。

GEThttp://localhost:22743/AbpUserConfiguration/GetAllnet :: ERR_FAILED

asp.net angular core aspnetboilerplate
1个回答
0
投票

appsettings.json

{
  "Origins": [
    "http://localhost:4200",
  ]
}

Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowedOrigins",
                    builder =>
                    {
                        builder
                            .WithOrigins(Configuration.GetSection("Origins").GetChildren().Select(c => c.Value)
                                .ToArray())
                            .AllowAnyHeader()
                            .AllowAnyMethod()
                            .AllowCredentials();
                    });
            });
        }
© www.soinside.com 2019 - 2024. All rights reserved.