vue项目中已拦截跨源请求:同源策略禁止读取位于....(原因:CORS 请求未能成功)解决方案
手动给Global.asax配置,添加如下方法最后记得退出所有终端,重新进入终端即可解决跨域报错问题。
·
手动给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");
}
}
最后记得退出所有终端,重新进入终端即可解决跨域报错问题。
更多推荐
已为社区贡献3条内容
所有评论(0)