目前在ASP.NET MVC中是这么处理的:
context.Response.AddHeader("Access-Control-Allow-Origin", $"http://{host}");
"Access-Control-Allow-Origin"不支持设置多个值,后来采取的解决方法:
var origin = context.Request.Headers.Get("Origin"); var protocol = (origin !=null && origin.StartsWith("https")) ? "https" : "http"; context.Response.AddHeader("Access-Control-Allow-Origin", $"{protocol}://{host}");