手动给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");
            }
        }

最后记得退出所有终端,重新进入终端即可解决跨域报错问题。

Logo

前往低代码交流专区

更多推荐