必须在 public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHost host) 首行加上
app.Use(async (context, next) => { context.Response.OnStarting(() => { var origin = context.Request.Headers["Origin"]; if (origin.Count > 0) { if (context.Request.Method == System.Net.Http.HttpMethod.Options.Method) context.Response.Headers.Add("Access-Control-Allow-Headers", "*"); context.Response.Headers.Add("Access-Control-Allow-Origin", origin); context.Response.Headers.Add("Access-Control-Allow-Credentials", new string[] { "true" }); } return System.Threading.Tasks.Task.CompletedTask; }); await next(); });
评论列表,共 0 条评论
暂无评论