using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; namespace Learn.VideoAnalysis.Expand { /// /// /// public static class CorsExpand { /// /// 添加跨域拓展 /// /// public static void AddCorsExpand(this IServiceCollection services) { services.AddCors(c => { c.AddPolicy("All", policy => { policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); } /// /// 使用跨域 /// /// public static void UseCorsExpand(this WebApplication app) { app.UseCors("All"); // 获取配置文件中的允许跨域的地址 app.UseCors(options => { options.WithOrigins("*") // 允许跨域请求的地址 .AllowAnyHeader() // 允许的请求标头 .AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等) }); } } }