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
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();
});
});
}