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(),要不然无法进行下面的请求