ASP.NET Framework 处理OPTION请求

在Global.aspx文件里添加

    protected void Application_BeginRequest()
        {
            if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
            {
                HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", Request.Headers["Origin"]);
                HttpContext.Current.Response.StatusCode = 204;
            }
        }

  此方法不需要Response.End(),要不然无法进行下面的请求

posted @ 2019-07-08 11:01  zengxia  阅读(1171)  评论(0编辑  收藏  举报