net core 3.1 跨域
1、在Startup.cs文件中配置全局变量
public readonly string any = "any";
2、在【ConfigureServices】方法中设置,注意位置,需要在AddMvc之后
services.AddCors(m => m.AddPolicy(any, a => a.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials()));
3、在【Configure】方法中添加,注意位置
app.UseCors(any);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapControllers().RequireCors(any);
});