|
|
@ -25,13 +25,15 @@ namespace CorsServer.WebApi31
|
|
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
services.AddCors(setup =>
|
|
|
|
#region Config
|
|
|
|
{
|
|
|
|
services.Configure<CorsOption>();
|
|
|
|
setup.AddPolicy(CorsName, build =>
|
|
|
|
#endregion
|
|
|
|
{
|
|
|
|
#region CORS
|
|
|
|
build.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("x-custom-error");
|
|
|
|
AddCors_1(services);
|
|
|
|
});
|
|
|
|
//AddCors_2(services);
|
|
|
|
});
|
|
|
|
//AddCors_3(services);
|
|
|
|
|
|
|
|
//AddCors_4(services);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
services.AddControllers();
|
|
|
|
services.AddControllers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -56,5 +58,60 @@ namespace CorsServer.WebApi31
|
|
|
|
endpoints.MapControllers();
|
|
|
|
endpoints.MapControllers();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IServiceCollection AddCors_1(IServiceCollection services)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services.AddCors(setup =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setup.AddPolicy(CorsName, build =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
build
|
|
|
|
|
|
|
|
.AllowAnyOrigin()
|
|
|
|
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
|
|
|
.WithExposedHeaders("x-custom-error");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IServiceCollection AddCors_2(IServiceCollection services)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services.AddCors(setup =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setup.AddPolicy(CorsName, build =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
build.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("x-custom-error");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IServiceCollection AddCors_3(IServiceCollection services)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services.AddCors(setup =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setup.AddPolicy(CorsName, build =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
build.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("x-custom-error");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IServiceCollection AddCors_4(IServiceCollection services)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services.AddCors(setup =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setup.AddPolicy(CorsName, build =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
build.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().WithExposedHeaders("x-custom-error");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|