在 .NET Core WebAPI 中,允许跨域请求
2023-11-15
public void ConfigureServices(IServiceCollection services)
{
    services.AddCors(options =>
    {
        options.AddPolicy("AllowAll", builder =>
        {
            builder.AllowAnyOrigin()
                   .AllowAnyMethod()
                   .AllowAnyHeader();
        });
    });
    
    // other service configurations
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // other app configurations

    app.UseCors("AllowAll");
    
    // other app configurations
}