本文主要是介绍CORS预检响应未成功,已拦截跨源请求:同源策略禁止读取位于,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
已拦截跨源请求:同源策略禁止读取位于 http://47.55.32.128:8081/abj_api/Login/GetRoleFunctions?roleId=800 的远程资源。(原因:CORS 请求未能成功)。
后台接口提供方需要做如下修改:
Global.asax配置,添加如下方法
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");//response.AddHeader("Access-Control-Allow-Methods", "GET, POST,PUT, DELETE");//response.AddHeader("Access-Control-Allow-Headers", "Content-Type");}}
这篇关于CORS预检响应未成功,已拦截跨源请求:同源策略禁止读取位于的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!