CORS预检响应未成功,已拦截跨源请求:同源策略禁止读取位于

时间:2025-01-21 10:52:55
protected void Application_BeginRequest(object sender, EventArgs e) { System.Web.HttpApplication app = sender as System.Web.HttpApplication; HttpResponse response = app.Response; //支持跨域 if (app.Request.HttpMethod == "OPTIONS") { //支持跨域 response.AddHeader("Access-Control-Allow-Methods", "*"); response.AddHeader("Access-Control-Allow-Headers", "*"); response.AddHeader("Access-Control-Allow-Origin", "*"); response.AddHeader("Cache-Control", "no-cache"); response.StatusCode = 200; response.End(); } else { response.AddHeader("Access-Control-Allow-Origin", "*"); response.AddHeader("Access-Control-Allow-Headers", "*"); response.AddHeader("Access-Control-Allow-Methods", "*"); response.AddHeader("Cache-Control", "no-cache"); //("Access-Control-Allow-Methods", "GET, POST,PUT, DELETE"); //("Access-Control-Allow-Headers", "Content-Type"); } }