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);
            });

 

 

posted @ 2021-02-23 10:36  疯狂阿坤  阅读(107)  评论(0编辑  收藏  举报