1 添加 cors 引用
2 按以下红字设置
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using WebApi.Authorization; namespace WebApi { public class Startup { // add services to the DI container public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddControllers(); } // configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); // global cors policy app.UseCors(x => x .AllowAnyMethod() .AllowAnyHeader() .SetIsOriginAllowed(origin => true) // allow any origin .AllowCredentials()); // allow credentials // custom jwt auth middleware app.UseMiddleware<JwtMiddleware>(); app.UseEndpoints(x => x.MapControllers()); } } }